Skip to content

Instantly share code, notes, and snippets.

@RobLBaker
Last active February 15, 2023 16:19
Show Gist options
  • Save RobLBaker/4f9f083fb23ec6f1ba7f13935bef8440 to your computer and use it in GitHub Desktop.
Save RobLBaker/4f9f083fb23ec6f1ba7f13935bef8440 to your computer and use it in GitHub Desktop.
Installing and Updating Problematic R packages
# A gist describing common problems (and solutions) when R packages won't update.
# This gist is divided into sections with each section representing a common or known problem.
# At the beginning of each section is a short description of the problem and the R output that likely prompted you to look for this gist.
# Following the problem is code for one or more potential solutions to try.
# These problems and solutions are aimed at National Park Service users and may be specific to government systems
# (i.e. user likely does not have admin rights so those solutions are not included).
##############################################
#### cannot download packages from github ####
##############################################
# download from github fails:
devtools::install_github("nationalparkservice/NPSdataverse")
# Error in utils::download.file(url, path, method = method, quiet = quiet, :
# download from 'https://api.github.com/repos/nationalparkservice/NPSdataverse/tarball/HEAD' failed
#1. reset .Renviron file download options:
options(download.file.method = "wininet")
#2. ignore warnings abuot deprecated methods
#3. retry package installation:
devtools::install_github("nationalparkservice/NPSdataverse")
##############################################
#############################################
#### github times out/requires token ########
#############################################
#1. See this much more informative gist on using github with R/Rstudio:
# https://gist.github.com/Z3tt/3dab3535007acf108391649766409421
#############################################
##############################################
##### Loaded Package won't update ############
##############################################
#If the package is already loaded:
install.packages("cli")
# Error in install.packages : Updating loaded packages
#1. unload and detach the package
detach("package:cli", unload = TRUE)
#2. then try again:
install.packages("cli")
##############################################
##############################################
##### Permissions Denied! ####################
##############################################
# R cannot remove a previous version of a package and gives you "permissions denied".
# You likely DO have permissions to write to this location
# The problem is the '00LOCK' directory, which has locked you out of the folder.
install.package("cli")
#... some time later these messages crop up:
#package ‘cli’ successfully unpacked and MD5 sums checked
#Warning: cannot remove prior installation of package ‘cli’
#Warning: restored ‘cli’
#In file.copy(savedcopy, lib, recursive = TRUE) :
# problem copying C:\Users\rlbaker\AppData\Local\R\win-library\4.2\00LOCK\cli\libs\x64\cli.dll to C:\Users\rlbaker\AppData\Local\R\win-library\4.2\cli\libs\x64\cli.dll: Permission denied
##############################################
# Solution 1: attempt to remove the 00LOCK folder in R:
#1. install a package management package...very meta.
install.packages("pacman")
#2. remove the 00LOCK folder (or attempt to)
pacman::p_unlock(lib.loc = pacman::p_path())
#if successful:
#The following 00LOCK has been deleted:
#/Users/rlbaker/AppData/Local/R/win-library/4.2/00LOCK-cli following 00LOCK has been deleted:
#if unsuccessful:
#No 00LOCK detected in:
#C:/Users/rlbaker/AppData/Local/R/win-library/4.2
#. retry package installation:
install.packages("cli")
##############################################
# Solution 2: manually remove the offending package using windows file explorer:
#1. Locate packages:
.libPaths()
#[1] "C:/Users/rlbaker/AppData/Local/R/win-library/4.2"
#[2] "C:/Program Files/R/R-4.2.0/library"
#2. Navigate to the package in windows explorer and delete it.
#3. Restart R/Rstudio, and try the install again.
##############################################
##############################################
##### Manage Package Locations ###############
##############################################
# Where are my packages being saved?
.libPaths()
#[1] "C:/Users/rlbaker/AppData/Local/R/win-library/4.2"
#[2] "C:/Program Files/R/R-4.2.0/library"
# Swap the existing default library locations:
.libPaths( c(.libPaths()[2], .libPaths()[1]) )
## add a new or different library location:
#1. In windows explorer, make a new folder (or find an existing one).
#2. Add the folder as the default location for packages:
.libPaths( c("C:/Users/rlbaker/documents/my_new_packages", .libPaths() )
##############################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment