首页 > 解决方案 > 在 R 4.0.0 之前安装了包“XXX”:请重新安装

问题描述

我正在使用 R 4.0.2。

我从cfcdae这里手动安装2 个软件包。我按照此处的说明下载了 Rtools 并使用它来安装上面的软件包。Stats5303lib

问题是

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

但是,当我尝试运行库时遇到以下问题时。

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

我在下面尝试过,但仍然是徒劳的。

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

为什么会这样?是不是因为包太旧了?

更新:

根据要求,我已经改变了我.libPaths()的如下并更新了SessionInfo()

> .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  

标签: r

解决方案


所有软件包都需要在新版本(4.0)下重新安装。我必须先删除然后重新安装所有软件包。

以下对我有用:

# 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)})

推荐阅读