iskandarblue
iskandarblue

Reputation: 7526

Rmarkdown does not find library path

Using macOS 10.12, I am trying to knit an Rmd file from the terminal. I have just installed R from homebrew, but when I try the following:

$ Rscript -e "rmarkdown::render('test.Rmd')"

An error appears:

Error in loadNamespace(name) : there is no package called ‘rmarkdown’
Calls: :: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

I am assuming, base on this related question, that one would need to export the library.

So I tried in R Studio:

> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library"

and then in the terminal:

$ export R_LIB= usr/Library/Frameworks/R.framework/Versions/3.3/Resources/library

but this throws an error:

-bash: export: `usr/Library/Frameworks/R.framework/Versions/3.3/Resources/library': not a valid identifier

Any suggestions on how to proceed from here would be much appreciated!

Upvotes: 1

Views: 1939

Answers (1)

miken32
miken32

Reputation: 42712

You cannot have spaces around the = sign when assigning in bash. This is the cause of the "not a valid identifier" error.

export R_LIB=usr/Library/Frameworks/R.framework/Versions/3.3/Resources/library

This will solve your Bash problem, but I'm not sure what you're trying to accomplish in R. I find it exceeding unlikely that you have a usr/Library directory. You can set an environment variable called R_LIBS_USER that tells R where to look for user-specific libraries, as well as R_LIBS:

The library search path is initialized at startup from the environment variable R_LIBS (which should be a colon-separated list of directories at which R library trees are rooted) followed by those in environment variable R_LIBS_USER. Only directories which exist at the time will be included.

By default R_LIBS is unset, and R_LIBS_USER is set to directory ‘R/R.version$platform-library/x.y’ of the home directory (or ‘Library/R/x.y/library’ for CRAN macOS builds), for R x.y.z.

I suspect you may be looking for:

export R_LIBS=/Library/Frameworks/R.framework/Versions/3.3/Resources/library

Or, if it's user specific:

export R_LIBS=$HOME/Library/Frameworks/R.framework/Versions/3.3/Resources/library

Upvotes: 1

Related Questions