5

Sometimes GNU R has a problem whereby Hadley Wickham recommends:

I'd recommend re-installing all your packages.

The question is how to do this in the best possible way. I know that install.packages or update.packages will upgrade all package versions and overwrite existing versions:

update.packages(checkBuilt = TRUE, ask = FALSE)

When using CRAN packages (nothing special from GitHub or other sources), this naive approach worked for me:

my.packages <- rownames(installed.packages());
install.packages(my.packages);

What can I do if I have installed dev versions from GitHub, for example, or used some local packages that are not shared publicly?

What I am looking for is a way to:

  1. check which changes to packages result from new installation (upgrades/downgrades);
  2. install packages again from the same source; and
  3. back up my old packages folder.

How can I address these requirements?

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
flexponsive
  • 6,060
  • 8
  • 26
  • 41

2 Answers2

2

Partial solution for (1) - find out which packages will be upgraded/downgraded:

my.packages <- installed.packages();
my.avail <- available.packages();

z <- merge(
      my.packages[,c("Package","Version")],
      my.avail[,c("Package","Version")],
      by = "Package", suffixes = c('.my','.avail'));

z$Version.my <- as.character(z$Version.my)
z$Version.avail <- as.character(z$Version.avail)

# my packages which will be upgraded
subset(z, Version.my < Version.avail)

# my packages that will be downgraded
subset(z, Version.my > Version.avail)

This is only approximate, I think - depending on dependencies you may not get all the upgrades. But you should see the downgrades to expect if using dev versions?

Another way to upgrade all packages is to use the following:

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
flexponsive
  • 6,060
  • 8
  • 26
  • 41
1

You can try the following method.

libLoc<-.libPaths()[1]
update.packages(lib.loc = libLoc, instlib = libLoc, checkBuilt = TRUE, ask = FALSE)

Here lib.loc is the location of the existing packages you want to update and instlib is the location for the new packages(same in the above example snippet). Avoid passing lib.loc or set it to NULL if you want to update all existing packages(not just the ones in libLoc) but place all the new updated packages in instlib location. Check out the documentation of update.packages function for more information.

I used this when I had issues with packages and had to reinstall them after upgrading to R-3.5 from older version on a remote system where I had limited privileges.

Hope this helps.

iMajetyHK
  • 157
  • 1
  • 1
  • 7