This set of scripts help convert the output of
Rmd files to
docx files. It is done by creating a clean
html file, then opening, converting, and saving the
docx using Applescript and Microsoft Word.
The workhorse script is a
makefile. Just change the variables to convert any
docx. However, only clean (not standalone)
html files will fully convert. There are some caveats (outlined below) if you want to keep a standalone
In this repo, the
The output files
The main support file
makefile automatically downloads the
html2docx.sh conversion script using
wget if it's missing. (Requires unix command-line tool
wget to download if missing.)
Optional support files
These files are listed to show that folks can cite references (useful for academics). To learn more about these RMarkdown
yaml options, see this RStudio post.
- Microsoft Word for Mac in your Applications folder. This has been built and testing using Microsoft Word for Mac, Version
- An understanding of how to use GNU Make and terminal commands.
How to Use
There are two options for going from
docx. The first
make option is
all and the second is
alt. But before anything, make sure the
makefile variables are set up accordingly. Simply change the
RMD_NAME variable to suite your needs:
RMD_NAME = example.Rmd
In this case, the
Rmd file of interest is
Although one can knit an
html file from a
Rmd file---letting knitr run the
pandoc step---there is a caveat.
FALSE. Otherwise, Microsoft Word will crash during the
docxconversion. Keep in mind that this is the default option for
rmarkdown. But I force it to be true in the
You cannot convert a self contained (aka standalone)
html file to a
docx. (At least I've found that it always crashes.) If you want the option to have a standalone
html file, then then we use option
This will produce a clean (not self contained)
html, create a
docx file, then replace the clean
html file with a standalone file.
It's a little hackish, but it allows you to create a
docx AND keep a standalone
First Run, Word will ask for permission
When you first run the script, do not worry if Word asks for permissions. Once you give Word access to the folder and files, it should run just fine and without asking again every time after.
Footnotes, not matter what, go to the bottom of the page. Just how html files work.
A special thanks to Andrew Heiss, from whom I've learned almost all I know about makefiles and converting markdown files to docx files.