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

Asked

Viewed 790 times

3

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

Also, 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.

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

  • 1

    Exporting from a already downloaded computer? Any reason not to install directly from the repositories on the other computer?

  • 1

    take a look at Packrat: https://rstudio.github.io/packrat/

  • 1

    Thanks for the tips! Molx - Yes of packages already installed and thinking of cases that of computers without internet connection, or create a backup of all installed packages. Daniel - I will look and then gave you a Feedback.

  • 1

    Revolution Analytics has the Reproducible R Toolkit aiming at environment portability, the only point is that they use their repository (the MRAN) and not the CRAN, although they maintain a periodic synchronization with the CRAN.

  • 1

    Daniel - the package Packrat package is cool! Wilson - I will check the Reproduclible R Toolkit... thanks in advance!

  • 1

    Cool @Jean! If you can use it, you could write an answer teaching the basics, so the next ones to search will already have the answer :)

  • 1

    Jewel! I’ll do it as soon as I’m done testing it. : D

Show 2 more comments

1 answer

2


Look at 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 3.2 its version of R and paste into the new computer that has R without the packets, taking care of the compatibility of the R version of the source and target computer.

Another way and in your script test if you have the packages and if you don’t have to install them, 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) 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.