Tou Mou
Tou Mou

Reputation: 1274

How to migrate Rstudio files and installed packages ( by version to a new computer )

Good afternoon !

I need to migrate a full installation of Rstudio to a new computer.

My old computer contains two versions of Rstudio.

I had tried the following code :

installed <- as.data.frame(installed.packages())

write.csv(installed, 'installed_previously.csv')

installedPreviously <- read.csv('installed_previously.csv')

baseR <- as.data.frame(installed.packages())

toInstall <- setdiff(installedPreviously, baseR)

What I need to is to list the installed versions of Rstudio ( with their associated installed packages ). After that , I need to copy all R code files .

I'm searching a script that automate this migration.

Thank you for help !

Upvotes: 2

Views: 1220

Answers (1)

IRTFM
IRTFM

Reputation: 263451

I suppose the first thing to do would be to make sure that the set of currently installed packages is up-to-date. Then build a target string of package names. This would be one possible methods.

  update.packages(checkBuilt=TRUE, ask=FALSE)  #check spelling of arguments
  new_pacs <- paste( setdiff( installedPreviously$Package, baseR$Package), 
                       collapse=",")
  install.packages( new_pacs, dependencies=TRUE)

If this is a really big set of packages then it's very possible that you will need to repeat steps 2 and 3 a few times. The management of dependencies is not sophisticated, and it's likely that there will be packages which have "second cousins" that are not named in the DESCRIPTION files of package being installed at the beginning. It's even possible that you might want to limit the number of package installed as a group to say 30 at a time. That would allow you to identify some of the missing but critical packages early in the process.

Another method (which seems cumbersome but was effective) used in the past is to simply copy the entire contents of an existing library directory to the new directory (excluding any that are already there by refusing to overwrite.) And then run the update.packages call above.

Yet another method would be to depend on the Packrat system. It's now built into the Rstudio project management tools.

Upvotes: 2

Related Questions