I currently have a project designed around one master Rmarkdown file (called full_document.Rmd), that in turn calls a series of other Rmarkdown files to render the whole document. As it's a complicated build process, I've automated the whole thing with a makefile. This has worked fine on another computer (running Windows 2010). However, I've tried re-running the makefile on a new PC (Windows 10), and it's running into a makefile specific error.
The makefile will run as expected until in encounters this line:
R --vanilla --slave -e "rmarkdown::render('paper_sections/full_document.Rmd',output_file = 'full_document.pdf')"
At which point, it returns this error message:
Error: object 'rmarkdown' not found
Execution halted
make: *** [Makefile:17: main] Error 1
Which implies that it is unable to find the rmarkdown package. However: compiling the document by just pressing knit in Rstudio works fine, so the package is installed fine. I also tried running this via the terminal in Rstudio, using the exact same command as above, and it also runs fine, which means the rmarkdown package is available to R run from the terminal. What I can't understand is why it wouldn't be usable from the process the makefile is running.
Any help on this would be really appreciated. I don't even know how to make this example reproducible, since as I said, it works fine on a different computer with basically the same setup.
Unfortunately, I haven't tried this myself (on my bucket list), so no assurances can be given that I'm not setting you off on a wild goose chase. But I've always found it productive to first look at path problems in these situations.
Thanks for the reply! That's a great suggestion. However, I don't think it's the issue; I just tried adding two lines to my build file:
R --vanilla --slave -e "cat(.libPaths(),file='libpath.txt')"
R --vanilla --slave -e "cat(rownames(installed.packages()),file='libraries.txt')"`
Just to see what the path looked like for the terminal session, and the text files it returned showed that it has the same path as what's available in Rstudio, and all of the same packages (including rmarkdown, annoyingly!). So it's got to be another issue beyond the path.
I figured it out! For anyone who has this problem in the future:
make did not like the use of rmarkdown::render(.... The error stems from the use of the double colons, likely because the colon is a protected character in make. I couldn't figure out how to escape the colons so they'd get parsed, but I was able to get it running by changing the line to: