Hi there - I'm using R Markdown to write an analysis report, and I'd like to output it as a word document.
However, every time I knit .Rmd file to Word, a folder would be generated automatically. As the following screenshot shows, I knitted the "Test.Rmd" file six times and six additional folders were created.
What happened to the R markdown on my device. This situation didn't happen before. How should I handle this to just knitting the .Rmd to the Word document, not generating a folder at the same time?
By default, word document is not creating any folder. Here is a small example of the default behavior
# dummy work dir for the example
dir.create(temp_dir <- tempfile())
old <- setwd(temp_dir)
# we create a Rmd with docx output
xfun::write_utf8(c(
"---",
"title: a docx",
"output: rmarkdown::word_document",
"---",
"",
"# A title",
"Some content with a plot",
"",
"```{r}",
"plot(iris)",
"```",
""
), "test.Rmd"
)
# only the Rmd doc
list.files(all.files = TRUE)
#> [1] "." ".." "test.Rmd"
# we render
rmarkdown::render("test.Rmd", quiet = T)
# only the docx document in addition
list.files(all.files = TRUE)
#> [1] "." ".." "test.docx" "test.Rmd"
setwd(old)
unlink(temp_dir)
Created on 2020-02-12 by the reprex package (v0.3.0.9001)
You see there is only the docx file created in the folder where the Rmd is. We need more information to understand what happens. Can you provide a Rmd example with this behavior ?
With Rmarkdown issue, it is very important to know what is inside your document. Also, with all type of issue, it helps us a lot if we can reproduce on our hand. Currently, we can't.
Some question to help:
Which version of Rmarkdown are you using ? packageVersion("rmarkdown")
Which version of pandoc ? rmarkdown::pandoc_version()
Using rmarkdown::render(filepath) in the console, everything works fine. No additonal folder would be created. However, when I use the "Knit to Word" button in RStudio, additional folder would be created.
There's nothing special in my document. Even I just render a newly created template .Rmd file, using the Knit button, there will be an additional folder created.
If I hit "Extract", an additional folder will be created. And this notification won't show up when I knit .Rmd next time. So as I modify and knit .Rmd repeatedly, I'll get many unnecessary folders created automatically.
If I hit "Cancel", it won't create an additional folder, only .docx will be created, which is good. However, this notification will show again and again whenever I knit .Rmd.
Currently, in order to depress this behavior, I just uninstalled "The Unarchiver" application, which is used to open RAR on Mac. Now, when I "Knit to Word", no additional folder will be created.
I don't know why the knit procedure can activate "The Unarchiver" application to create an additional folder.
I don't think it is knit or rmarkdown. When you click render button or call render, Rmarkdown will call knit that will produce a md file from a Rmd file. Then it will call pandoc software as a converter to create the docx document from the md file.
Other thing to know: a docx document can be untar or unzip and it is just a bunch of folder and files like xml one. This is how the docx format is built. I guess pandoc will create those files, then will create the docx bundle using a archive command. Pandoc would require to use a archive tool to deal with docx. If you are curious, you can try uncompress a docx file and you will see what is inside.
That is why i think there is something with pandoc in your setup. Uninstalling is a solution, you could also try to not make the software the default for your system. Maybe there is a way to give the correct permission for all actions too.
However, as you get the issue only when using RStudio button, either the version of pandoc used in both case is not the same, or there could be an issue with the IDE. But I don't see what could happen because the IDE just calls rmarkdown::render and not pandoc directly.
Now that you found the issue, maybe someone will encounter the same ans share experience.
I know this could happen when you don't have Office installed. On macOS, if you don't have Office, Office files (e.g. .docx or .pptx) could be treated as archive files, and opened by decompressing tools (such as the Unarchiver you mentioned). In your case, it sounds like the .docx files are more strongly associated with the Unarchiver than Office. Or it could be an RStudio IDE bug.