Package Management in R, how to export and import packages?


I use my scripts on several computers and then I come across errors related to lack of packages and often such computers do not have internet access, which makes accessing the repositories difficult.

Furthermore, when I need to maintain the "machine" (format), it would be interesting to have a backup of the installed packages, this would save me time.

So I would like to know how I can manage my packages, export and import packages in R?


Look a very simple way is to copy the contents of the folder C:\Users\User\Documents\R\win-library\3.2 , or in place of your 3.2 version of R and paste in the new computer that has R without the packages, being careful about the compatibility of the R version of the source and destination computer.

Another way is in your script to test if you have the packages and if you don't have them installed, see (in this case you need internet):

 #lista dos pacotes necessários no seu script
list.of.packages <- c("hydroTSM", "lubridate",'openxlsx')

# encontra novos pacotes no pc
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] 

# instala todos eles
if(length(new.packages)) install.packages(new.packages) 
Scroll to Top