Rstudio knit pdf in Rstudio loadNamespace(name): t

2019-06-19 02:04发布

问题:

I just updated to Rstudio Version 0.98.1074. When I try to use compile notebook with a script or Knit pdf with an .rmd I get

Error in loadNamespace error: there is no package called 'rmarkdown'

yet I can type rmarkdown::render("filename.rmd") and it will render the document. I removed rmarkdown and re-installed with RStudio and it did not help. I've updated all my packages and I'm using R3.1.1.

This is a minor inconvenience since I have a workaround but thought I'd post in case there is a solution that I can't find.

回答1:

I received almost the exact same error when trying to use Rmarkdown on Windows, within Cygwin:

loadNamespace(name): there is no package called 'rmarkdown'

Everything worked fine within Rstudio, but didn't work when I tried to auto-knit some .Rmd files within Cygwin.

My library path in Rstudio:

.libPaths()
[1] "C:/Users/Gravitas/Documents/R/win-library/3.3" "C:/Program Files/R/R-3.3.2/library"

My library path as reported in Cygwin, when running C:\Program Files\R\R-3.3.2\bin\R.exe:

.libPaths()
[1] "C:/Program Files/R/R-3.3.2/library"

The problem:

  • When Rstudio is run in non-Administrator mode, it cannot write anything into C:/Program Files/R/R-3.3.2/library as this directory is write-protected.
  • Thus, Rstudio writes new packages into the user profile directory, which is freely writable.
  • However, Cygwin was not aware of the user's profile directory, so it could not find all of the newly installed packages.

The solution was to set this environment variable within Cygwin:

export R_LIB=C:/Users/Gravitas/Documents/R/win-library/3.3

Now, the path reported Cygwin is:

.libPaths()
[1] "C:/Users/Gravitas/Documents/R/win-library/3.3" "C:/Program Files/R/R-3.3.2/library"

And now, I can call bash scripts within Cygwin to auto-knit .Rmd files.