Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R_LIBS_USER ignored by R

Tags:

bash

r

I am using bash on Linux Centos. I set up the R_LIBS_USER from my $HOME/.bashrc. Also tried to set this up on $HOME/.Renviron

# in .bashrc
export R_LIBS_USER=$HOME/lib/R/site-library

cat .Renviron
R_LIBS_USER=$HOME/lib/R/site-library

I made sure R_LIBS_USER is set up properly. Echo show the proper value. However running R from this terminal that gives the proper value of R_LIBS_USER does not pick up this value.

> .libPaths()
[1] "/global/software/r/3.5.0/lib64/R/library"

The .libPaths() only shows the default library path in stead of my personal one. $HOME/lib/R/site-library is not in the output of .libPaths(). When I tried to load libraries inside $HOME/lib/site-library I got package not found error. I can add the personal path from inside R, then I can load libraries inside my personal R lib directory.

> .libPaths(c("/myhome/lib/R/site-library", .libPaths()))
> .libPaths()
[1] "/myhome/lib/R/site-library"                           
[2] "/global/software/r/3.5.0/lib64/R/library"

I have searched for two days to look for a solution. Other people had similar problems and also had no solutions. I used to be able to pick up the personal library path, but don't know what I changed that abolished this normal behavior.

like image 967
Kemin Zhou Avatar asked Dec 29 '18 06:12

Kemin Zhou


1 Answers

Finally figured it out, .Renviron file does not do expansion of variable $HOME, not like those in .bashrc. R_LIBS_USER variable will be set to $HOME/lib/R/site-library. This is an invalid path when $HOME is not expanded. R will not tell you that this is wrong. Just silently move on to its normal business (I think this is a design flaw in R, no exception handling).

.libPaths("/nonexistent/path") # has no effect on the result of .libPaths()
 # except that it will maintain the default R library and remove any exisiting
 # personal library. And will not tell you anything wrong with the nonexistent
 # directory

Before the .libPath("/nonexistent/path") call, I had two elements in the vector: one /default/R/library, ether other /my/persoanl/R/lib after the assignment only the former is left. R is full of surprises.

like image 70
Kemin Zhou Avatar answered Oct 24 '22 06:10

Kemin Zhou