Bookdown: render_book error when using r compile script

Hi all,

I have had two posts get closed about a render_book error before there is sufficient, in my opinion, resolution or insight into what I can do to fix the issue:

This first post brought to the attention of @cderv an issue that started with changes @rstudio made to bookdown_27 about render_book not finding some files (despite my believe that all the files are present). I provided a minimal working example (via a bitbucket repo, but was told no errors were found despite my evidence to the contrary.

In this second post, I tried to get some further insight into the problem by providing a snapshot of the sessionInfo() of an older machine I was using in which the render_book script worked. Unfortunately, for some reason I don't understand, this older machine is now giving me the same errors. The sessionInfo() upon discovering the error seems to not have changed, so I am not sure if pushes to the rmarkdown codebase are happening and being updated to my machine without my manually updating them.

I have tried all I really know to do, as a new user to RStudio/RMarkdown/Bookdown, which is why I was looking for clarity from the community.

Do making posts here constitute bug reports or do I have to go through a different process for that? It would help to know that what I am even experiencing is a bug. From my perspective, something used to work and now it doesn't. From a user perspective that seems to be a bug. Is it?

Perhaps I should ask a much simpler question know since my scripts don't seem to be working on any machine I have.

For those that use Bookdown/RMarkdown are you compiling your documents use the Knit button?
If so all the files seem to write to a folder _book, but what if you want all the relevant files to that .Rmd moved to a different folder (for organization sake). Do you move them all by script?

Also, if you want to compile the .Rmd to different formats (html, gitbook, epub, pdf), are you updating each time for each file format the YAML header data of the .Rmd which controls output format and output options?
To avoid this kind of annoyance I had a both _bookdown.yml and _output.yml files and renderscripts for each output file type that organized all of this information (as seen in minimal working example Bitbucket).

Do people have suggestions about your own workflows that you like? Or are we all to just intended to click the Knit button and change the YAML data all the time then manually move the files to more organized locations.

I am clearly backed into a corner now as the way I used to compile my work with render_book is no longer working on any machine I have, so I need to understand at least some functional way to compile.

I am happy to learn another way if someone can point me to a place that explains a good and practical workflow (file organization, multiple output formats needed, etc.)

Thank you.

Jason M. Osborne

So I can finally close this series of questions with the following conclusion:

  1. After learning to use the debug tools (break point, stepping into code) I learned that my problem stemmed from a dir.exists (in this case a folder called source-posts) being FALSE which then threw the error message that I have been asking about

  2. When looking into why dir.exists might be false when clearly on my file system I could see it exist lead to the following conclusion about my file structure

home folder
|
named.RProj
|
source-posts folder

It seems that while I created "home folder" as an "RProj" which should set "home folder" as the working directory this effect did not take place as seen in "RStudio" from the Tools -> Global Options -> Default Working Directory which was set to ~ instead of ~/homefolder as was expected.

When I manually input the home folder as my Default Directory and Re-compiled my renderscripts (as in

)

then everything works as normal.

So problem solved...I guess.

Is there something I have done wrong in assuming that making the folder as an Rproj should set the Default Directory? Are there reason why the .RProj might no longer work? Is it possible that in current versions of bookdown, RMarkdown, etc. that something is amiss with .RProj setting the Default Directory.

I am glad the fix was so simple in the end and not anything wrong with my render_book Makefile. It only took me weeks to find it :wink:

Hope this helps folks.

Best,

Jason M. Osborne

Sorry for the delay on this. and sorry... me again ! :wave:
Let me try to give answer to your comments. Feedbacks is always appreciated.

You can ask question and report strange behavior here. I'll be looking at the community for those. Bug reports are done in Github though in the specific repo where the issue is (i.e GitHub - rstudio/bookdown: Authoring Books and Technical Documents with R Markdown)

From user perspective that seems a bug, but sometimes it is not a bug in the codebase directly, but interaction with user environment or other packages. Asking here helps dig into that until reproduction to be sure to fill the issue in the right place.

With bookdown project, you can use the "Build" pane to build the all book. Clicking on the knit button will generate a preview of the the book. (meaning only the specific file and no updates to the whole book).
In console, render_book() will build the whole book. This is specific to projects like bookdown, blogdown, R Markdown website, distill website, ....
With single R Markdown document, you can render the document using the knit button.

All files are written to the output dir, _book by default, as this is how the bookdown package is designed when you are rendering books. (5.1 Build the book | bookdown: Authoring Books and Technical Documents with R Markdown)
Everything output of each Rmd are tied together to be seen as a single website following the gitbook() or bs4_book() format, or another. They share resources and links are modified accordingly. If you want another name that _book you can change the configuration
If you don't want a book structure or a book output, then you should not use the book format but just single documents.

The _output.yaml is the config file to store all your format.

the default output format will be the first output format specified in the YAML metadata of the first Rmd file or a separate YAML file _output.yml . If you plan to generate multiple output formats for a book, you are recommended to specify all formats in _output.yml .

You can then render all at once, or refer to them in render_book() directly. The build pane in RStudio IDE should allow you to choose which one to render too.

it seems your orgnization is correct and your way of doing also if you don't use the RStudio IDE button to render. (or because of you specific organization with subfolder).

Usually, a bookdown project is a single folder with the source file at the root, also with config file and output are written in _book output, and resources are organized in folder. _output.yaml contains all the formats which make rendering epub just a call like bookdown::render_book(output_format = "bookdown::epub_book") - as long as the default organization is followed. Otherwise, using non default value for argument is definitely ok.

is it possible that you don't see the build pane in the RStudio IDE ?
image

I think the Rstudio IDE expect to find a bookdown project as the root of the RStudio project, by looking in index.Rmd for

site: bookdown::bookdown_site

You can try cloning and opening the demo book (GitHub - rstudio/bookdown-demo: A minimal book example using bookdown) or create one of the template book to see how it looks like in a standard project

It is possible that you don't see the build pane because you were not in an opened RStudio project. Maybe

.Rproj is an IDE feature. You can open a project in the RStudio IDE by clicking on the file usually (with extension association on OS) or using "Open Project..." from the IDE file menu.
More on projects here: https://support.rstudio.com/hc/en-us/articles/200526207-Using-RStudio-Projects

To check that you are in the correct project, you need to see the project at the top of the IDE
image

It should shows "named" for you I think as you have a named.Rproj in your example. or rather BasicWebsite-WithPosts-Rmarkdownaccording to your bitbucket repo.

I am glad the fix was so simple in the end and not anything wrong with my render_book Makefile. It only took me weeks to find it :wink:

Sorry about that really... Glad you solved it finally !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.