Install multiple packages from a folder

5.2k Views Asked by At

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.

4

There are 4 best solutions below

0
On BEST ANSWER

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)
0
On

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")
0
On

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.

2
On

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 )