0

I need to set the library path in R for a single use (i.e. I do not want and can't set it in Rprofile.site and can't put the additional packages into the default library).

I tried to append to and to overwrite the library path with .libPaths() but neither worked; the path remained unchanged. See my attempts below.

Since I have seen examples that effectively are the same as my attempts, I have a feeling that it might be an authorisation issue: I simply have no rights to change the path.

I have searched stackoverflow, but the questions/solutions do not match my problem. Any suggestions? And no, turning it off and on again would not help.

My environment is Mac (High Sierra), R 3.4.3, RStudio 1.1.423, R newbie user (not root).

Thanks!

Original path

> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library"
> .Library
[1] "/Library/Frameworks/R.framework/Resources/library"

Trying to append

> .libPaths( c( .libPaths(), "<some_other_valid_path>") )
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library"
> .Library
[1] "/Library/Frameworks/R.framework/Resources/library"

Trying to overwrite

> .libPaths("<some_other_valid_path>")
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library"
> .Library
[1] "/Library/Frameworks/R.framework/Resources/library"
3
  • Mind sharing the exact value of "<some_other_valid_path>"? Are you, for instance, leaving on or removing any trailing "/" in the specification of the path? Commented Mar 1, 2018 at 21:26
  • I can't share the exact value, but it did not end with /. See, my answer below for explanation of the cause and solution. Commented Mar 2, 2018 at 11:58
  • Good to hear. If Dirk's answer solved your problem, you might want to give it a check mark to let others's know it's solved. Commented Mar 2, 2018 at 16:16

2 Answers 2

3

I think you just confused yourself. Just add one directory to prepend:

R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" 
[3] "/usr/lib/R/library"           
R> .libPaths("/tmp")
R> .libPaths()
[1] "/tmp"                    "/usr/local/lib/R/site-library" 
[3] "/usr/lib/R/site-library" "/usr/lib/R/library"           
R> 

The new one comes first and will therefore be used first for an installation, or a search via library() etc.

You cannot overwrite from an existing session---that is like cutting the tree branch you are sitting on.

But do see help(Startup). There are other files, even on a per-current-directory level, you could use.

0

Thanks for the feedback, Dirk! I was indeed confused about how .libPaths works, thanks for the clarification.

Based on your example, I realised that issue was that I had no access to the additional directory. .libPaths() internally calls dir.exists() which returned false due to non-accessibility and thus the new directory was not added to path. I just need to figure out how to provide access.

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