[R] scripts with littler

John Lawrence Aspden news at aspden.com
Wed Jan 10 13:12:56 CET 2007


John Lawrence Aspden wrote:

> I've got a library (brainwaver), installed locally in ~/R/library, and
> this information is recorded in the ~/.Renviron file.

> In my script I load the library, but if I call it using
> #!/usr/bin/r --vanilla, this stops working.

(Various private e-mails exchanged. Again, thanks Dirk!)

Just in case anyone else is trying to do this, it turns out that if you can
persuade your end users to install the library to ~/R/library, then you can
say:

#!/usr/bin/r --vanilla
library(brainwaver, lib.loc='~/R/library')

although in my case, brainwaver depends on another library, which it now
can't find, so actually I have to load them in order:

#!/usr/bin/r --vanilla

library(waveslim, lib.loc='~/R/library')
library(brainwaver, lib.loc='~/R/library')





Alternatively, 

#!/usr/bin/r --vanilla

.libPaths('~/R/library')
library(brainwaver)

works, although be careful, I've noticed that it seems to behave a bit
strangely on my debian setup.

e.g.

#!/usr/bin/r --vanilla
cat(.Library,'*****', .libPaths(),"\n")
.libPaths('~/R/library')
cat(.Library,'*****', .libPaths(),"\n")

gives output
/usr/lib/R/library
***** /usr/local/lib/R/site-library /usr/lib/R/site-library /usr/lib/R/library
/usr/lib/R/library ***** ~/R/library /usr/lib/R/library

that is, it seems to have removed /usr/local/lib/R/site-library
and /usr/lib/R/site-library as well as added ~/R/library

Cheers, John.

-- 
Contractor in Cambridge UK -- http://www.aspden.com



More information about the R-help mailing list