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

3

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

In addition, 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?

    
asked by anonymous 28.09.2015 / 02:57

1 answer

1

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

Another way in your script is to test if you have the packages and if you do not have them installed, see (in this case you need the 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) 
    
04.04.2016 / 19:36