-
-
Notifications
You must be signed in to change notification settings - Fork 979
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
rmarkdown uses incorrect working directory if filename has spaces and output format is "github_document" #1980
Comments
Reproduced. It seems the bug originally comes from |
I see issue comes from here, which removes Line 366 in 80f14b2
Then, if Lines 355 to 356 in 80f14b2
A workaround is to explicitly specifying Lines 369 to 372 in 80f14b2
I'll open a PR. |
@atusy what I don't understand correctly about this bug is why it works ok with dir.create(tmp_dir <- tempfile())
owd <- setwd(tmp_dir)
dir.create("subdir")
download.file("https://gist.githubusercontent.com/cboettig/5ba7013764152c1305bf26d81ec94fbe/raw/0b23bc008f816fdb80f9744da35d7ee78ba5ce4a/Bug%2520Report.Rmd",
"subdir/Bug Report.Rmd", quiet = TRUE)
# no error
rmarkdown::render("subdir/Bug Report.Rmd", output_format = "html_document", quiet = TRUE)
browseURL("Bug-Report.html")
# error
rmarkdown::render("subdir/Bug Report.Rmd", output_format = "md_document", quiet = TRUE)
#> Quitting from lines 8-10 (Bug-Report.Rmd)
#> Error: file.exists("Bug Report.Rmd") n'est pas TRUE
# browseURL("Bug-Report.html")
setwd(owd)
unlink(tmp_dir) The code you pointed out is the same for both formats, isn't it ? It seems both formats are not doing the same thing. Adding a
> fs::dir_tree()
.
+-- Bug-Report.Rmd
\-- subdir
\-- Bug Report.Rmd So in the second case, the initial Rmd file is not copied and in the first case it is copied. Also @cboettig the title of the issue is about a wrong working directory. However, the working directory (root dir of knitr chunk) is the same with both dir.create("subdir")
xfun::write_utf8(c(
"```{r}",
"getwd()",
"```"
), "subdir/Bug Report.Rmd")
res <- rmarkdown::render("subdir/Bug Report.Rmd", output_format = "html_document", quiet = TRUE)
#>[WARNING] This document format requires a nonempty <title> element.
#> Defaulting to 'Bug-Report.utf8' as the title.
#> To specify a title, use 'title' in metadata or --metadata title="...".
content <- xfun::read_utf8(res)
# getwd() folder of knitr chunk
xml2::xml_text(xml2::read_html(content[grepl("## ", content)]))
#>[1] "## [1] \"C:/Users/chris/AppData/Local/Temp/RtmpUN37nz/file969428684ff7\""
res <- rmarkdown::render("subdir/Bug Report.Rmd", output_format = "github_document", quiet = TRUE)
content <- xfun::read_utf8(res)
# Same dir as above
content[grepl("## ", content)]
#>[1] " ## [1] \"C:/Users/chris/AppData/Local/Temp/RtmpUN37nz/file969428684ff7\""
setwd(owd)
unlink(tmp_dir) Did I missed something ? I would like to understand better the real issue here and currently the reprex is not very clear as it mixes the issue presented first here with what it told in the title here. |
So about the issue reported by @cboettig and shown in the initial reprex, which is working for This is because However, I believe this is an undesired side effect which is hiding the issue and there is something not right in the way paths and directories are handled when there is a space. And I think you tried to fix that @atusy. I need to look closer on how this should work and why we get this weird behavior |
@cderv Thanks for the follow up. I also guessed |
By filing an issue to this repo, I promise that
xfun::session_info('rmarkdown')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('rstudio/rmarkdown')
.I understand that my issue may be closed if I don't fulfill my promises.
As you can in the reprex below, all this does is create a trivial Rmarkdown document in a subdirectory, and then attempt to knit it. Because the RMarkdown document has a space in the name and we have requested
github_document
, the example errors by having the wrong working directory (the root dir, not the same dir from where the Rmarkdown file is found, as in the usual convention!) Change the output format tohtml_document
, or remove the space in the name, and the error is resolved.Consider the following reprex:
Created on 2020-12-14 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: