7

I upgraded R to v2.14.0 and along with the upgrade I decided to move the standard package repository to Dropbox so laptop and desktop are in sync all the time. I set my R_LIBS=/Dropbox/ToolBox/R/packages in .Renviron and when 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 a .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 invoke R from Sweave it only picks up the standard repository.I have created Renviron.site, Rprofile.site, read help(Startup) following similar questions q1 , and q2 with no success.

Could anybody shed me some light (step by step) on how to fix this issue please?

Update: When I sweave my .Snw from within R it picks up all the right folders. I am not sure why when is done from textmate does something different.

Any ideas?

2
  • +1 for documenting the research you've already done on this somewhat confusing aspect of R. Commented Dec 16, 2011 at 19:19
  • It may matter how you're starting Sweave; this question is about a similar issue, where TeXShop was doing something different than just running at the command line so the right environment variables had to be changed in a different way. stackoverflow.com/q/7509395/210673 Commented Dec 16, 2011 at 19:30

2 Answers 2

3

Thanks to Josh I realised that the problem was not on R itself but in textmate.

Neither of Sweave and R bundles were picking up my local repository due to option --vanilla was set on as default in both bundles.

Here it is my solution:

R Bundle

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

Sweave Bundle

  1. In Textmate go to Bundles>Bundles Editor>Show Bundles Editor
  2. Click on Sweave bundle to expand
  3. Go to Sweave, Typset & View and scroll down until you see the following line:echo -e "setwd('$SW')\nSweave('$TM_FILEPATH')" | R --vanilla --quiet | pre
  4. Change --vanilla to --save
  5. Reload bundle

Happy days are back again :-)

0
1

Try putting a line like this in your "Rprofile.site" file, located in $R_HOME/etc/. (Here, $R_HOME is the directory returned by running R.home() in an active R session.)

(You'll also want to remove (perhaps temporarily) any ".Rprofile" files from: (a) your home directory; and (b) the current directory (from which R/Sweave is being launched).)

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

Then, if that doesn't solve the problem outright (and it sure works for me), Sweave and then apply LaTeX to a skeletal .Snw document that includes the following chunk.

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

The output should provide some useful hints to the source of your problem.

5
  • I did as you mentioned and unfortunately did not work. This is the ouput from the above chunk:R.home() [1] "/Library/Frameworks/R.framework/Resources" > .libPaths() [1] "/Library/Frameworks/R.framework/Versions/2.14/Resources/library"
    – Altons
    Commented Dec 16, 2011 at 19:28
  • That seems like an odd value for R.home() (though it may be expected on a Mac). Given the directory pointed to by your default .libPaths() value, I'd hope to see something more like "/Library/Frameworks/R.framework/Versions/2.14/Resources". On my PC, R.home() returns "C:/R/R-2.14.0", which is the directory containing both R_HOME/library and R_HOME/etc (the directory containing "Rprofile.site" Commented Dec 16, 2011 at 19:48
  • 1
    It looks like this has to do with the location from which Sweave is being launched by TextMate. To confirm this, can you try Sweave("docName.Snw") from within an R session (rather than running Sweave from the command line or having TextMate launch it)? Commented Dec 16, 2011 at 19:55
  • Josh you are right. when I Sweave the file from within R it picks up all correctly. So I wonder what is going on when I sweave from within textmate?
    – Altons
    Commented Dec 16, 2011 at 21:04
  • No idea really, since this is essentially a textmate issue. As for solutions, you could try putting an etc/Rprofile.site in the directory textmate uses as R.home() directory when it runs Sweave for you. To get help from others, you might prominently edit your question to say what you've learned. Also, you could upvote this answer, since it did point to the source of your problem, as I had expected it would ;) Finally, do please update with whatever solution you eventually find. Commented Dec 16, 2011 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.