Sweave cannot load R packets

I upgraded R to v2.14.0, and along with the upgrade I decided to move the standard package repository to Dropbox, so that the laptop and desktop are in sync all the time. I set my R_LIBS=/Dropbox/ToolBox/R/packages to .Renviron , and when I open Rstudio or R.app (mac), I get the following commands:

 > Sys.getenv("R_LIBS") [1] "/Dropbox/Toolbox/R/packages" > .libPaths() [1] "/Dropbox/Toolbox/R/packages" [2] "/Library/Frameworks/R.framework/Versions/2.14/Resources/library" [3] "/Applications/RStudio.app/Contents/Resources/R/library 

but when I run the same commands in .Snw (Textmate + Sweave), I get:

 > Sys.getenv("R_LIBS") [1] "" > .libPaths() [1] "/Library/Frameworks/R.framework/Versions/2.14/Resources/library" 

As you can see above, when I call R from Sweave, it only picks up a standard repository. I created Renviron.site , Rprofile.site , read help(Startup) after similar q1 and q2 questions without success.

Can someone shed some light (step by step) on how to solve this problem?

Update: When I sweave my .Snw from inside R, it picks up all the correct folders. I am not sure why, when this is done from textmate, you are doing something else.

Any ideas?

+7
source share
2 answers

Thanks to Josh, I realized that the problem is not in R itself, but in textmate.

None of the Sweave and R packages built my local repository because of the option - vanilla was installed by default in both packages.

Here is my solution:

R bundle

  • Open a terminal and go to $ HOME / Library / Application Support / TextMate / Pristine Copy / Bundles.
  • Type >mate R.tmbundle , this will open the R package directly in textmate
  • There is a tmR.rb file in the support folder
  • Scroll down until you find this line: stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
  • Remove --vanilla option and save

Sweave bundle

  • In Textmate, go to Bundles> Bundles Editor> Show Bundles Editor
  • Click on the Sweave package to expand
  • Go to Sweave, Typset, and View and scroll down until you see the following line: echo -e "setwd('$SW')\nSweave('$TM_FILEPATH')" | R --vanilla --quiet | pre echo -e "setwd('$SW')\nSweave('$TM_FILEPATH')" | R --vanilla --quiet | pre
  • Change --vanilla to --save
  • Update package

Happy days again :-)

+3
source

Try putting the line in the "Rprofile.site" file located in $R_HOME/etc/ . (Here $R_HOME is the directory returned when R.home() started in an active R session.)

(You will also want to delete (possibly temporarily) any ".Rprofile" files from: (a) your home directory and (b) the current directory (from which R / Sweave starts).)

 .libPaths(c("/Dropbox/Toolbox/R/packages", .libPaths())) 

Then, if this does not solve the problem directly (and it probably works for me), Sweave, and then apply LaTeX to the skeleton .Snw document, which includes the following snippet.

 <<>>= R.home() .libPaths() @ 

The result should contain some useful hints for the source of your problem.

+1
source

All Articles