Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package ‘XXX’ was installed before R 4.0.0: please re-install it

Tags:

r

I am using R 4.0.2.

I manually installed 2 packages from cfcdae and Stats5303lib from here. I followed the instruction here to download Rtools and use it to install packages above.

Problem is

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron") # runs fine
Sys.which("make") #works fine
                               make 
"C:\\rtools40\\usr\\bin\\make.exe" 
install.packages("Stat5303libs_0.7-5.zip",repos=NULL,type="source") # these all run fine
install.packages("cfcdae_0.8-4.zip",repos=NULL,type="source")  # these all run fine

However, when I ran into problem below when I tried to run the libraries.

Error: package or namespace load failed for ‘cfcdae’:
 package ‘cfcdae’ was installed before R 4.0.0: please re-install it

I tried below but still in vain.

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

Why is this happening? Is it because the package is too old?

Update:

As requested, i have changed my .libPaths() as below and updated the SessionInfo() as well.

> .libPaths()
[1] "C:/Users/UserME/Documents/R/win-library/4.0"
[2] "C:/Program Files/R/R-4.0.2/library"   

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Hong Kong SAR.1252  LC_CTYPE=English_Hong Kong SAR.1252   
[3] LC_MONETARY=English_Hong Kong SAR.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_Hong Kong SAR.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6        rstudioapi_0.11     magrittr_1.5       
 [4] splines_4.0.2       MASS_7.3-51.6       tidyselect_1.1.0   
 [7] munsell_0.5.0       statmod_1.4.34      lattice_0.20-41    
[10] colorspace_1.4-1    R6_2.4.1            rlang_0.4.6        
[13] minqa_1.2.4         dplyr_1.0.0         tools_4.0.2        
[16] grid_4.0.2          nlme_3.1-148        gtable_0.3.0       
[19] ellipsis_0.3.1      lme4_1.1-23         tibble_3.0.1       
[22] lifecycle_0.2.0     numDeriv_2016.8-1.1 crayon_1.3.4       
[25] Matrix_1.2-18       nloptr_1.2.2.2      purrr_0.3.4        
[28] ggplot2_3.3.2       vctrs_0.3.1         glue_1.4.1         
[31] compiler_4.0.2      pillar_1.4.6        generics_0.0.2     
[34] scales_1.1.1        boot_1.3-25         lmerTest_3.1-2     
[37] pkgconfig_2.0.3  
like image 525
user1769197 Avatar asked Aug 13 '20 07:08

user1769197


People also ask

How do I update installed packages in R?

The easiest way to update R is to simply download the newest version. Install that, and it will overwrite your current version. There are also packages to do the updating: updateR for Mac, and installr for Windows.

Why is my R not installing packages?

Changing the configuration in R Studio to solve install packages issue. Go To Tools -> Global option -> Packages. Then uncheck the option “Use secure download method for HTTP”. For other RStudio issues refer to official Troubleshooting Guide here.

Do I have to reinstall R packages?

Once the package is installed, you keep that in your R library associated with your current major version of R. You will need to update & reinstall packages each time you update a major version of R.


1 Answers

All packages need to be reinstalled under the new version (4.0). I had to first remove and then reinstall all the packages.

The following worked for me:

# check your package library path 
.libPaths()

# grab old packages names
old_packages <- installed.packages(lib.loc = "/Library/Frameworks/R.framework/Versions/3.6/Resources/library")
old_packages <- as.data.frame(old_packages)
list.of.packages <- unlist(old_packages$Package)

# remove old packages 
remove.packages( installed.packages( priority = "NA" )[,1] )

# reinstall all packages 
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
lapply(list.of.packages,function(x){library(x,character.only=TRUE)})
like image 169
Amleto Avatar answered Sep 21 '22 08:09

Amleto