Install R package to a specific directory

2020-07-06 08:02发布

I tried this code to install R package to a directory where I stored my R packages.

install.packages("zoo", lib="/data/Rpackages/")

I got this warning message:

Warning in install.packages("zoo", lib = "/data/Rpackages/") : 'lib = "/data/Rpackages/"' is not writable

Secondly how do I create a file .Renviron in our home area and add the line R_LIBS=/data/Rpackages/ to it?

标签: r
3条回答
聊天终结者
2楼-- · 2020-07-06 08:32

Try running R studio as administrator. If you are using ubuntu start R using sudo R

查看更多
乱世女痞
3楼-- · 2020-07-06 08:40

How do you actually get out of the warning situation? Is there a better way other than (in R Studio menus) Session->Interrupt R and terminating the R session? I tried CTRL-C.

> install.packages("car", lib="/my R packages/")
Warning in install.packages :
  'lib = "/my R packages/"' is not writable

My solution to the problem was to load the package within R Studio using the 'Packages' window which then does the following:

> install.packages("car")
Installing package into ‘C:/Users/33386/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.1/car_2.0-21.zip'
Content type 'application/zip' length 1332800 bytes (1.3 Mb)
opened URL
downloaded 1.3 Mb

package ‘car’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\33386\AppData\Local\Temp\RtmpKWnZD4\downloaded_packages
> 
查看更多
何必那么认真
4楼-- · 2020-07-06 08:45

Briefly:

  1. Use chmod to change the directory mode: chmod u+w /data/R/packages. You may need sudo (or your admin) to do that.

  2. Use an editor and create and save a file: editor ~/.Renviron. You could also copy Renviron.site from R's etc/ directory and start from that.

查看更多
登录 后发表回答