How to Update a Package in R

How to update a package in R?

You can't do this I'm afraid, well, not with update.packages(). You need to call install.packages("R2jags") instead.

You can't install R2jags in the current session because you have already loaded the current version into the session. If you need to, save any objects you can't easily recreate, and quit out of R. Then start a new R session, immediately run install.packages("R2jags"), then once finished, load the package and reload in any previously saved objects. You could try to unload the package with:

detach(package:R2jags, unload = TRUE)

but it is quite complex to do this cleanly unless the package cleans up after itself.

update.packages() exists to update all outdated packages in a stated library location. That library location is given by the first argument (if not supplied it works on all known library locations for the current R session). Hence you were asking it the update the packages in library location R2jags which is most unlikely to exist on your R installation.

How to update all packages for a new R version quickly and easily?

Don't know if this is quick and easy, but I think the pacman package can be useful.

  1. Under the previous version, use pacman::p_lib() to return a vector of your installed packages, and save them onto disk use saveRDS().

For instance,

mypks <- pacman::p_lib()
saveRDS(mypks, "~/mypks.rds")

  1. Update R.

  2. Import the vector from step 1 using readRDS() and run install.packages() with the object.

For instance,

mypks <- readRDS("~/mypks.rds")
install.packages(mypks)

Update a specific R package and its dependencies

As Ben indicated in his comment, you need to get the dependencies for fields, then filter out the packages with Priority "Base" or "Recommended", and then pass that list of package to install.packages() to deal with the installation. Something like:

instPkgPlusDeps <- function(pkg, install = FALSE,
which = c("Depends", "Imports", "LinkingTo"),
inc.pkg = TRUE) {
stopifnot(require("tools")) ## load tools
ap <- available.packages() ## takes a minute on first use
## get dependencies for pkg recursively through all dependencies
deps <- package_dependencies(pkg, db = ap, which = which, recursive = TRUE)
## the next line can generate warnings; I think these are harmless
## returns the Priority field. `NA` indicates not Base or Recommended
pri <- sapply(deps[[1]], packageDescription, fields = "Priority")
## filter out Base & Recommended pkgs - we want the `NA` entries
deps <- deps[[1]][is.na(pri)]
## install pkg too?
if (inc.pkg) {
deps = c(pkg, deps)
}
## are we installing?
if (install) {
install.packages(deps)
}
deps ## return dependencies
}

This gives:

R> instPkgPlusDeps("fields")
Loading required package: tools
[1] "fields" "spam" "maps"

which matches with

> packageDescription("fields", fields = "Depends")
[1] "R (>= 2.13), methods, spam, maps"

You get warnings from the sapply() line if a dependency in deps is not actually installed. I think these are harmless as the returned value in that case is NA and we use that to indicate packages we want to install. I doubt it will affect you if you have 4000 packages installed.

The default is not to install packages but just return the list of dependencies. I figured this was safest as you may not realise the chain of dependencies implied and end up installing hundreds of packages accidentally. Pass in install = TRUE if you are happy to install the packages indicated.

Note that I restrict the types of dependencies searched for - things balloon if you use which = "most" - fields has over 300 such dependencies once you recursively resolve those dependences (which include Suggests: fields too). which = "all" will look for everything, including Enhances: which will be a bigger list of packages again. See ?tools::package_dependencies for valid inputs for the which argument.

I need to update a package

Have you tried restarting your R session? It works fine in my RStudio.

If you have issues installing the package from the CRAN Repository, try this:

devtools::install_github("edzer/sp")

It will return these outputs

Downloading GitHub repo edzer/sp@HEAD
√ checking for file 'C:\Users\Users\AppData\Local\Temp\RtmpSOAQPV\remotes242444575da6\edzer-sp-2ace7ca/DESCRIPTION' (952ms)
- preparing 'sp': (8.6s)
√ checking DESCRIPTION meta-information ...
- cleaning src
- checking for LF line-endings in source and make files and shell scripts (2s)
- checking for empty or unneeded directories
- looking to see if a 'data/datalist' file should be added
- building 'sp_1.4-5.tar.gz'

Installing package into ‘C:/Users/Users/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
* installing *source* package 'sp' ...
** using staged installation
** libs

*** arch - i386
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c Rcentroid.c -o Rcentroid.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c gcdist.c -o gcdist.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c init.c -o init.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c pip.c -o pip.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c pip2.c -o pip2.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c sp_xports.c -o sp_xports.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c surfaceArea.c -o surfaceArea.o
/mingw32/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c zerodist.c -o zerodist.o
/mingw32/bin/gcc -shared -s -static-libgcc -o sp.dll tmp.def Rcentroid.o gcdist.o init.o pip.o pip2.o sp_xports.o surfaceArea.o zerodist.o -LC:/PROGRA~1/R/R-41~1.0/bin/i386 -lR
installing to C:/Users/Documents/R/win-library/4.1/00LOCK-sp/00new/sp/libs/i386

*** arch - x64
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c Rcentroid.c -o Rcentroid.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c gcdist.c -o gcdist.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c init.c -o init.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c pip.c -o pip.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c pip2.c -o pip2.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c sp_xports.c -o sp_xports.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c surfaceArea.c -o surfaceArea.o
/mingw64/bin/gcc -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c zerodist.c -o zerodist.o
/mingw64/bin/gcc -shared -s -static-libgcc -o sp.dll tmp.def Rcentroid.o gcdist.o init.o pip.o pip2.o sp_xports.o surfaceArea.o zerodist.o -LC:/PROGRA~1/R/R-41~1.0/bin/x64 -lR
installing to C:/Users/Documents/R/win-library/4.1/00LOCK-sp/00new/sp/libs/x64
** R
** data
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'sp'
finding HTML links ... done
00sp html
CRS-class html
DMS-class html
GridTopology-class html
Line-class html
Line html
Lines-class html
Polygon-class html
Polygons-class html
Rlogo html
Spatial-class html
REDIRECT:topic coordinates<-,Spatial-method -> Spatial-class.html [ FAIL ]
REDIRECT:topic [[<-,Spatial,ANY,missing-method -> Spatial-class.html [ FAIL ]
REDIRECT:topic [<-,Spatial-method -> Spatial-class.html [ FAIL ]
REDIRECT:topic $<-,Spatial-method -> Spatial-class.html [ FAIL ]
SpatialGrid-class html
SpatialGrid html
SpatialGridDataFrame-class html
SpatialGridDataFrame html
SpatialLines-class html
SpatialLines html
SpatialLinesDataFrame-class html
SpatialMultiPoints-class html
REDIRECT:topic $<-,SpatialMultiPoints,character-method -> SpatialMultiPoints-class.html [ FAIL ]
SpatialMultiPoints html
SpatialMultiPointsDataFrame-class html
SpatialPixels-class html
SpatialPixelsDataFrame-class html
SpatialPoints-class html
REDIRECT:topic $<-,SpatialPoints,character-method -> SpatialPoints-class.html [ FAIL ]
SpatialPoints html
SpatialPointsDataFrame-class html
SpatialPolygons-class html
SpatialPolygons html
SpatialPolygonsDataFrame-class html
addattr html
aggregate html
as.SpatialPolygons.GridTopology html
as.SpatialPolygons.PolygonsList html
asciigrid html
bbox html
bpy.colors html
bubble html
char2dms html
compassRose html
coordinates-methods html
REDIRECT:topic coordinates<-,data.frame-method -> coordinates-methods.html [ FAIL ]
coordinates html
REDIRECT:topic coordinates<- -> coordinates.html [ FAIL ]
coordnames-methods html
REDIRECT:topic coordnames<- -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,SpatialPoints,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,SpatialMultiPoints,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,SpatialLines,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,Lines,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,Line,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,SpatialPolygons,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,GridTopology,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,SpatialGrid,character-method -> coordnames-methods.html [ FAIL ]
REDIRECT:topic coordnames<-,SpatialPixels,character-method -> coordnames-methods.html [ FAIL ]
degaxis html
dimensions html
disaggregate html
flip html
geometry-methods html
REDIRECT:topic geometry<- -> geometry-methods.html [ FAIL ]
REDIRECT:topic geometry<-,data.frame,Spatial-method -> geometry-methods.html [ FAIL ]
gridded-methods html
REDIRECT:topic fullgrid<- -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<- -> gridded-methods.html [ FAIL ]
REDIRECT:topic fullgrid<-,Spatial,ANY-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic fullgrid<-,SpatialGrid,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic fullgrid<-,SpatialGridDataFrame,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic fullgrid<-,SpatialPixels,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic fullgrid<-,SpatialPixelsDataFrame,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialGrid,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialGridDataFrame,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialPixels,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialPixelsDataFrame,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialPoints,list-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialPoints,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialPointsDataFrame,list-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,SpatialPointsDataFrame,logical-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,data.frame,GridTopology-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,data.frame,character-method -> gridded-methods.html [ FAIL ]
REDIRECT:topic gridded<-,data.frame,formula-method -> gridded-methods.html [ FAIL ]
gridindex2nb html
gridlines html
image html
is.projected html
REDIRECT:topic proj4string<- -> is.projected.html [ FAIL ]
REDIRECT:topic proj4string<-,Spatial,CRS-method -> is.projected.html [ FAIL ]
REDIRECT:topic proj4string<-,Spatial,character-method -> is.projected.html [ FAIL ]
loadmeuse html
mapasp html
merge html
meuse html
meuse.grid html
meuse.grid_ll html
meuse.riv html
over html
panel html
point.in.polygon html
polygons-methods html
REDIRECT:topic polygons<-,data.frame,SpatialPolygons-method -> polygons-methods.html [ FAIL ]
polygons html
REDIRECT:topic polygons<- -> polygons.html [ FAIL ]
REDIRECT:topic Previous alias or file overwritten by alias: C:/Users/Documents/R/win-library/4.1/00LOCK-sp/00new/sp/help/polygons.html
recenter-methods html
select.spatial html
sp-deprecated html
spChFIDs-methods html
REDIRECT:topic spChFIDs<- -> spChFIDs-methods.html [ FAIL ]
REDIRECT:topic spChFIDs<-,Spatial-method -> spChFIDs-methods.html [ FAIL ]
spDistsN1 html
spTransform html
spplot html
spsample html
stack html
surfaceArea html
zerodist html
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (sp)

After the install finishes, load the package by

library(sp)

Otherwise, if it still return errors. Try downloading the package from here and install them to RStudio manually

R package updates

Restart R and run install.packages again. On Windows, you can't update a package that's already loaded, if the package contains compiled C/C++/Fortran code. This includes dplyr and rlang.

To be doubly sure, before you run install.packages, go to your R packages directory (C:/Users/tomsp/OneDrive/Documents/R/win-library/3.5) and delete any zero-length files that are present. These are artifacts of failed install attempts and will break install.packages if present.

updating package in R: `update.packages` vs. `install.packages`

This is yet another reason why I prefer to launch both the "install" and "update" operations outside of my current, working R session.

By using the command-line, I get fresh R sessions without loaded packages, and the issue you experienced here does not arise. And as a shortcut, I define scripts update.r and install.r using littler (and included in the examples/ directory of that package) but you can of course do the same via Rscript.

update.packages() repeatedly asks me for EVERY package. How do I stop it?

See in the help for update.packages (?update.packages):

ask:
logical indicating whether to ask the user to select packages
before they are downloaded and installed, or the character string
"graphics", which brings up a widget to allow the user to (de-)select
from the list of packages which could be updated. (The latter value
only works on systems with a GUI version of select.list, and is
otherwise equivalent to ask = TRUE.)

So the behaviour you are expecting can be accomplished with the following:

update.packages(ask = FALSE)

The c in y/n/c simply means cancel and stops the update process completely. Another trick to speed things up is to set the number of cores used for installing packages: e.g., update.packages(ask = FALSE, Ncpus = 3L).



Related Topics



Leave a reply



Submit