Error: Input files not all in same directory, please supply explicit wd
Asked Answered
S

3

7

After trying to build a PDF that worked ~2 weeks ago, no fuss, on a new machine with a fresh install of R, R studio, bookdown, etc, I have this error:

Error: Input files not all in same directory, please supply explicit wd

I have chapters of .Rmd files sorted into directories, and so if I change rmd_subdir from true to false, the error goes away, but... I just can't work with 100+ chapters containing 4-7 each scenes in the root of the project; I'll go insane.

I have new_session: no in my _bookdown.yml, but that's not helping matters.

I don't know enough about R to even begin to diagnose this - Google returns 4 (!) results and all of them are source code. As such, I'm not sure which files to include here, so please let me know, and I'll paste them in.

How I Build

I press the button that says Build Book in RStudio, and it ticks along and exits with status 1 and the above error after a moment.

The exact error message

==> rmarkdown::render_site(output_format = 'bookdown::gitbook', encoding = 'UTF-8')



processing file: book-book.Rmd
  |......................................................................| 100%
  ordinary text without R code


output file: book-book.knit.md

Error: Input files not all in same directory, please supply explicit wd
Execution halted

Exited with status 1.

index.Rmd

---
title: "F"
author: "TTil"
site: bookdown::bookdown_site
fontsize: 10pt
geometry: paperwidth=6in,paperheight=9in,margin=0.5in,heightrounded,twoside,includehead,includefoot,heightrounded
output:
  bookdown::gitbook:
    split_by: section
    config:
      toolbar:
        position: static
  bookdown::pdf_book:
    keep_tex: yes
    latex_engine: lualatex
    includes:
      in_header: preamble.tex
      before_body: before_body.tex
documentclass: book
link-citations: yes
linestretch: 1.15
links-as-notes: true
mainfont: "Inter"
---

_bookdown.yml

book_filename: 'book-book'
language:
  ui:
    chapter_name: ''
delete_merged_file: true
new_session: no
rmd_subdir: true

# Before We Begin {-}

test test replace me

My file structure looks like this:

index.Rmd
  - part-1/
     - ch01/
       - sc01.Rmd
       - sc02.Rmd
       ...
     - ch02/
     ...
  - part-2/
  ... 

and thus I expect sc01.Rmd and sc02.Rmd to become Chapter One, and then it and its siblings to be Part One, and so on and so forth for Part Two, Part Three, ...

As I've said above, this PDF was working as-is 2 weeksish ago (albeit on a different machine).

Cheers.

Selffulfillment answered 25/6, 2020 at 15:22 Comment(2)
If you post the part of your code that isn't working, or a small reproducible example, it will make it easier to figure out what is going wrong.Facetiae
There's no part that isn't working, the whole thing won't build. I understand why you (have to) ask, but I really can't be more specific, or distill this issue any further. This is, like, the third time I've even touched R or R Markdown or anything of this kind, so...Selffulfillment
D
8

Update: This has been fixed in the dev version of bookdown: https://github.com/rstudio/bookdown You can install it via remotes::install_github('rstudio/bookdown').


This might be related to a recent feature in bookdown. Since you didn't provide a reproducible example, my blind guess is that setting options(bookdown.render.file_scope = FALSE) might fix it. You can set this option in either your Rmd document or ~/.Rprofile.

Derosier answered 25/6, 2020 at 19:53 Comment(9)
I encountered this error and your fix worked for me. I also tried passing an explicit working directory via the argument knit_root_dir but this did not work. In general there are some use cases for keeping source documents in different directories, e.g. generating stand-alone quarterly reports and also a combined annual report that reuses a subset of files in from each quarterly report.Garald
Thank you so much!!! I'm not sure I would have ever found this out on my own, the error message isn't very intuitive.Selffulfillment
I feel this could be a bug of bookdown v0.20. I'll investigate more when I have a chance. Sorry for the trouble, and thanks for your patience!Derosier
Yeah, this has also broken the use of Rmd-files for front and back matter in a subdirectory in oxforddown - error disappears when commenting out rmd_subdir: ["front-and-back-matter"] in _bookdown.yml (but then the appendices, which live in this directory, aren't included)Tera
It was fixed by changing my Makefile's build settings from Rscript -e 'bookdown::render_book("index.Rmd", output_format = "bookdown::pdf_book")' to Rscript -e 'options(bookdown.render.file_scope = FALSE); bookdown::render_book("index.Rmd", output_format = "bookdown::pdf_book")'Tera
I had the same error after upgrading to v0.20. Adding options(bookdown.render.file_scope = FALSE) to index.Rmd didn't help. I went back to v0.18 and the Error went away.Slue
This has been fixed in the dev version of bookdown: github.com/rstudio/bookdown You can install it via remotes::install_github('rstudio/bookdown'). I'm still trying to find time to make a new release to CRAN. Sorry.Derosier
@YihuiXie I just did an install from github but it didn't fix it. The option setting did. I guess someone may also need a restart between installs if the grab it during troubleshooting?Lawannalawbreaker
@StephLocke Yes, when installing R packages on Windows, it's a good idea to restart R excessively (before and after installing a package). I'm planning to make a CRAN release of bookdown this week. Hopefully this problem will be gone soon.Derosier
H
1

Just something complementary to Yihui's answer. If I added the line options(bookdown.render.file_scope = FALSE) to the R markdown file, it did not work. It worked great if this line was added to the ~/.Rprofile file.

Hosmer answered 30/9, 2020 at 21:29 Comment(0)
T
-1

Similar problem: the command Rscript -e "bookdown::render_book(input='index.Rmd', output_format='bookdown::gitbook', config_file='_py-rse.yml')" runs fine from the command-line with bookdown 0.19, but fails with bookdown 0.20 (installed today), giving the message Error: Input files not all in same directory, please supply explicit wd. The configuration file _py-rse.yml (below) does indeed have files in multiple directories - we have to do this because we are building several books in the same project (that share some chapters and appendices). I'll try again with the next update to bookdown; if the bug persists, I'll try to create a reprex.

book_filename: "py-rse"
language:
  label:
    fig: "Figure "
    tab: "Table "
  ui:
    chapter_name: "Chapter "
output_dir: "_book/py-rse"
delete_merged_file: false
rmd_files:
  - index.Rmd
  - py-rse/bash-basics.Rmd
  - py-rse/bash-advanced.Rmd
  - py-rse/scripting.Rmd
  - py-rse/git-cmdline.Rmd
  - py-rse/git-advanced.Rmd
  - py-rse/automate.Rmd
  - py-rse/config.Rmd
  - py-rse/errors.Rmd
  - py-rse/teams.Rmd
  - py-rse/style.Rmd
  - py-rse/project.Rmd
  - py-rse/testing.Rmd
  - py-rse/packaging.Rmd
  - py-rse/publish.Rmd
  - py-rse/finale.Rmd

  # End files
  - appendix.Rmd
  - LICENSE.md
  - CONDUCT.md
  - CONTRIBUTING.md
  - gloss.md
  - py-rse/install.Rmd
  - py-rse/objectives.Rmd
  - py-rse/keypoints.Rmd
  - py-rse/solutions.Rmd
  - py-rse/yaml.Rmd
  - py-rse/ssh.Rmd
  - references.Rmd
  - links.md
Torin answered 4/7, 2020 at 19:5 Comment(1)
A colleague found a fix. His explanation: "the problem is that adding the footnote feature required that each rmd file start in a new session. And when it runs in a new session it builds the document in the folder that it resides in, but bookdown builds under the main project folder. The fix is to stop the footnote feature from happening." Our build line is now options(bookdown.render.file_scope = FALSE); bookdown::render_book(input='index.Rmd', output_format='bookdown::gitbook'\ , config_file='_py-rse.yml')Torin

© 2022 - 2024 — McMap. All rights reserved.