Change R default library path using .libPaths in Rprofile.site fails to work

后端 未结 15 2851
青春惊慌失措
青春惊慌失措 2020-11-22 06:27

I am running R on Windows, not as an administrator. When I install a package, the following command doesn\'t work:

> install.packages(\"zoo\")
Installing          


        
15条回答
  •  孤城傲影
    2020-11-22 06:52

    I found what I think is a solution here (thank you Carl Schwarz at SFU) for adding a personal library that is permanently (you don't have to define it each session) recognized whether using R or Rstudio, and Rstudio treats it as the default on my Mac machine. I hadn't seen it laid out this explicitly on SO, so I summarized the steps they provided, for Windows and then for Mac.

    For a Windows 7 OS:

    1. Create a directory on the drive where you want to have your personal library, e.g. C:\User\Rlibs (or another that you have permissions to)

    2. Search for/go to "Edit environment variable for your account" in the Windows search bar to edit control panel settings

    3. Click "New..." in the middle of the "Environmental Variables" window

    4. In the "New User Variable" window, type R_LIBS for the "Variable name", and the path to the personal library directory you created, e.g. C:\User\Rlibs

    5. Click OK and you should see the Variable/Value pair in the User variables window

    6. Click OK again

    Now when you start R (or Rstudio) and type the command .libPaths() you should see the personal library you created as well as the R system library.

    For Mac:

    1. In your "Home" or "username" directory create a folder called Rlibs

    2. Launch the Terminal application

    3. Type: echo "R_LIBS=~/Rlibs"> .Renvrion Make sure case matches.

    4. Type ls -a to see the full list of files in the directory, which should now include .Renvrion

    5. Verify that the .Renviron file has been set properly: more .Renviron

    Launch R/Rstudio and type .libPaths() and you should see the new path to your personal library.

提交回复
热议问题