Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knit Directory setting can break R Markdown websites #2158

Closed
jdblischak opened this issue Feb 8, 2018 · 9 comments
Closed

Knit Directory setting can break R Markdown websites #2158

jdblischak opened this issue Feb 8, 2018 · 9 comments
Labels
Milestone

Comments

@jdblischak
Copy link
Contributor

System details

RStudio Edition : Desktop
RStudio Version : 1.1.423
OS Version      : Ubuntu 17.10 (artful)
R Version       : 3.4.3

Steps to reproduce the problem

  1. Create an empty file called _site.yml
  2. Open a new R Markdown file and save it as index.Rmd in the same directory as _site.yml
  3. Set the Knit Directory to Document Directory
  4. Click Knit (it works)
  5. Set the Knit Directory to Current Directory
  6. Click Knit (error)

Describe the problem in detail

RStudio v1.1 introduced a new feature to change the knit directory via PR #904. This new feature causes problems for R Markdown websites. The argument knit_root_dir can be passed directly to rmarkdown::render, but RStudio uses rmarkdown::render_site if it detects a website. Because rmarkdown::render_site does not have the argument knit_root_dir, it throws an error like the following:

Error in rmarkdown::render_site("/home/jdb-work/index.Rmd", encoding = "",  : 
  unused argument (knit_root_dir = "~")
Execution halted

Describe the behavior you expected

Since rmarkdown::render_site does not have the argument knit_root_dir, I expected RStudio to ignore the Knit Directory setting when executing rmarkdown::render_site.

I am using rmarkdown 1.8, which is the latest CRAN release. Please let me know if there is any other information that would be useful.

@ronblum
Copy link
Contributor

ronblum commented Feb 12, 2018

@jdblischak Thank you for notifying us of this issue!

Both "Current Working Directory" and "Project Directory" result in this error when not working in a project. However, when working in a project, these work.

@jjallaire
Copy link
Member

@jmcphers If this really breaks render_site this might be a candidate for a patch release.

@jdblischak
Copy link
Contributor Author

However, when working in a project, these work.

@ronblum I cannot replicate this. Even in the context of an RStudio project, I still get the same error when either "Current Working Directory" or "Project Directory" is set. In both cases, the argument knit_root_dir is passed to render_site, which causes an error. Could you please provide the steps you took that allowed you to run render_site via RStudio without error?

My directory structure looked like this:

$ tree .
.
├── index.Rmd
├── _site.yml
└── test-render_site.Rproj

0 directories, 3 files

@ronblum
Copy link
Contributor

ronblum commented Feb 12, 2018

Sorry! Ignore my previous comment—I left out a step when I created a project instead of no-project. It fails there, too.

@ronblum ronblum added high and removed medium labels Feb 12, 2018
@jdblischak
Copy link
Contributor Author

A minor follow up. This will also affect the Getting Started directions for bookdown since bookdown uses rmarkdown::render_site.

@jmcphers
Copy link
Member

@jdblischak Thanks very much for reporting this! We missed this combination when setting up the Knit in Directory feature set. I've just pushed a fix, and will make the fix part of the next 1.1 release should we roll one.

Hopefully it won't be likely in the wild as people are unlikely to try to swap the knit directory when working with websites!

@jdblischak
Copy link
Contributor Author

Thanks very much for reporting this! We missed this combination when setting up the Knit in Directory feature set. I've just pushed a fix, and will make the fix part of the next 1.1 release should we roll one.

Thanks for fixing this, @jmcphers! I look forward to the next release.

Hopefully it won't be likely in the wild as people are unlikely to try to swap the knit directory when working with websites!

Interesting. What makes you say that? I'd assume the opposite. With just a few R Markdown files, it is easy enough to save them in the directory where you want them to be executed (i.e. no need to change the knit directory). On the other hand, with a website with many R Markdown files, it is cumbersome to save them all in the place to be executed, especially if you want the files to be executed from the project directory.

@mikoontz
Copy link

mikoontz commented Mar 6, 2018

I just did this in the wild! (Broke my website by having "Evaluate chunks in directory: Project" set from another session and got a unused argument (knit_root_dir = "~") error). Switching the Knit Directory back to the Document Directory fixed the issue.

I was playing around with the "Evaluate chunks in directory" dropdown menu in RStudio -> Preferences -> R Markdown to see if it did what I thought it did, and didn't realize I could also change it under the "Knit" dropdown menu.

Not sure whether this is related, but the dropdown menu for "Evaluate chunks in directory" in the RStudio -> Preferences -> R Markdown doesn't seem to reflect the currently set Knit Directory. It always shows "Document" even if I switch it to "Project", hit "Okay", have the Rmd successfully knit using the Project directory as the knit directory, then go back to the RStudio -> Preferences -> RMarkdown tab. The checkbox under the Knit -> Knit Directory dropdown does move between "Project Directory" and "Document Directory". Is this expected behavior?

@jdblischak
Copy link
Contributor Author

Not sure whether this is related, but the dropdown menu for "Evaluate chunks in directory" in the RStudio -> Preferences -> R Markdown doesn't seem to reflect the currently set Knit Directory. It always shows "Document" even if I switch it to "Project", hit "Okay", have the Rmd successfully knit using the Project directory as the knit directory, then go back to the RStudio -> Preferences -> RMarkdown tab. The checkbox under the Knit -> Knit Directory dropdown does move between "Project Directory" and "Document Directory". Is this expected behavior?

@mikoontz I observe the same behavior with RStudio Desktop 1.1.423. Changing the Knit Directory with the dropdown menu does change the Knit Directory, but it is always reset to Document if I go back to the settings.

It would be really convenient if this option (and really so many options) could be easily specified in an RStudio project file to allow for different behaviors in different projects. Changing the Knit Directory for one project doesn't mean I want to use that Knit Directory for every single R markdown file I execute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants