I am writing a document with knitr and latex on linux. I made a small makefile to automate the build. It works perfectly fine on linux, but it is problematic on windows. Issuing make I get
C:\Users\samde_000\Documents\GaussianProcess-Course>make
mkdir -p build && \
cp src/GPcourse.Rnw build/GPcourse.Rnw && \
cd build && \
Rscript -e "library(knitr); knit(\"GPcourse.Rnw\")"
Error in library(knitr) : there is no package called 'knitr'
Execution halted
So I checked this to pin down the problem:
C:\Users\samde_000\Documents\GaussianProcess-Course>Rscript -e ".libPaths()"
[1] "C:/Users/samde_000/Documents/R/win-library/3.2"
[2] "C:/Program Files/R/R-3.2.2/library"
C:\Users\samde_000\Documents\GaussianProcess-Course>Rscript -e "library(knitr)"
So when using make, the package cannot be found. But manually issuing the same commands, the package can be found.
To absolutely make sure that difference is due to using make, I altered the Makefile a little to output the R search path:
C:\Users\samde_000\Documents\GaussianProcess-Course>make
mkdir -p build && \
cp src/GPcourse.Rnw build/GPcourse.Rnw && \
cd build && \
Rscript -e ".libPaths()" && \
Rscript -e "library(knitr); knit(\"GPcourse.Rnw\")"
[1] "C:/Program Files/R/R-3.2.2/library"
Error in library(knitr) : there is no package called 'knitr'
Execution halted
This shows that when make issues the commands. The search path is somehow altered to only contain "C:/Program Files/R/R-3.2.2/library"
.
If I am correct, make issues all recipes in a subshell. So maybe this is causing trouble somehow? Anyway, I don't have much experience with windows, and I don't know how I can keep the same R search path while using make.
The reason why I am asking this is because a co-author works on windows. So the makefile should be compatible with both linux and windows.