简体   繁体   中英

Install multiple packages from a folder

I have a folder that contains all libraries I used (>100 zipped binary files) in a previous computer. Now I switched to a new computer. And I want all these packages installed in R in new machine. New machine doesn't have direct internet connection due to data it is hosting. So I can't install them directly. I also don't want to install each of them manually. Is there a way I can automate this process and make R read the folder, and install the packages in that folder? Thank you in advance.

I guess functions like list.files and grep may help here?

I use Windows 7, and R 3.1.0.

try this

setwd("path/packages/") #set the working directory to the path of the packages
pkgs <- list.files()

install.packages(c(print(as.character(pkgs), collapse="\",\"")), repos = NULL)

We were having 300+ packages on non-internet server.So we copied all the packages to a specified directory.

setwd("location/to/a/specified/directory") #set the working directory to the path of the packages
pkgs1 <- list.files()

install.packages(pkgs1 , repos = NULL, type = source )

I had to add type = "binary" to make it work for me.

setwd("path/packages/") #set the working directory to the path of the packages
pkgs <- list.files()

install.packages(c(print(as.character(pkgs), collapse="\",\"")), repos = NULL, type= "binary")

If you are on ubuntu or any other linux distribution. Identify the tmp folder where the downloaded packages are stored. Usually it is the "/tmp/Rtmp" folder. You need to the set the working directory to this folder.

               setwd("location of the directory")
               pkg <- list.files()
               install.packages(pkg, repos = NULL, type = "source")

This works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM