Knit .Rmd file to Word would generate an additional folder automatically

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?

Many thanks for your help!

Is clean not set to TRUE when you're calling render()?

Is your issue essentially the inverse of this question: knit the output, but also keep the intermediate objects ?

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
  "title: a docx",
  "output: rmarkdown::word_document",
  "# A title",
  "Some content with a plot",
), "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"

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()

Thank you

For reference, there is also an issue open with the same question

Reminder: FAQ: Is it OK if I cross-post?

Thank you so much for your guidance.

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.

Therefore, I was wondering whether should change the behavior of this button and how to do it. The version of related packages are:

#> [1] '1.14'
#> [1] '2.3.1'

Created on 2020-02-12 by the reprex package (v0.3.0)

Many thanks for your help!

Thanks for your advice.

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.

That makes more sense. What version of RStudio are you running?

This might be related: What is the difference between running chunk and knitting it?

Thanks. The RStudio Version is 1.2.5033

It's easy to reproduce this situation on my device:

  1. Create a new R Markdown file - the default without any edits is suitable for this issue
  2. Using the Knit menu, "Knit to Word"

I'm using:

  • Mac,
  • RStudio 1.2.5033
  • rmarkdown 2.1.1
  • pandoc version 2.3.1

In addition, if I run rmarkdown:render(filepath) in the console to render .Rmd, the additional folder won't be created.

Hi, I think I've found the problem.

  1. I create a new project. Everything is new.
  2. Create a R Markdown file.
  3. Using the Knit menu, "Knit to Word"

Then, my device gives me this:

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.

I need to check how to turn off this behavior.


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.


Well done ! I think this is definitely the issue.

I don't think it is knit or rmarkdown. When you click render button or call render, Rmarkdown will call knit :package: 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.


Many thanks for your guidance. Really learned a lot!

1 Like

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.

1 Like