简体   繁体   中英

Cannot load package in R

Since yesterday, I cannot load some common used packages, eg reshape2 and stringr through library command.

Step to reproduce my problem:

1) Start a new session in Rstudio server (Version 0.99.467). I also kill the active-sessions in Rstudio server.

2) Run these codes

library(ggplot2)
library(stringr)

3) Get an error message:

Error in unloadNamespace(package) : namespace 'stringr' is imported by 'reshape2' so cannot be unloaded Show Traceback

Rerun with Debug

Error in library(stringr) : “stringr” version 0.6.2 cannot be unloaded.

But I don't get error if stringr is loaded before ggplot2 . How should I fix this problem. Thanks for any suggestions.

I may have to update R to 3.2

My R session info:

R version 3.1.3 (2015-03-09)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8    LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] ggplot2_1.0.0

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     grid_3.1.3       gtable_0.1.2     MASS_7.3-39      munsell_0.4.2    plyr_1.8.1      
 [8] proto_0.3-10     Rcpp_0.11.2      reshape2_1.4     scales_0.2.4     stringr_0.6.2    tools_3.1.3    

I resolved my problem through updating R and all R packages.

I guess the problem is caused by old version of stringr or reshape2 as I install the same packages in different places (system folder or personal library). R tried to load a old version of package.

Even though it is a good practice to update R for me it was not necessary to solve the same issue. The problem can result from few .libPaths() . With .libPaths("C:/Program Files/R/R-3.4.3patched/library") you can point out one folder. After that just reinstall of packages, and it should work. My code:

> .libPaths()

[1] "L:/My Documents/R/win-library/3.4"         "C:/Program Files/R/R-3.4.3patched/library"

> .libPaths("C:/Program Files/R/R-3.4.3patched/library")

> packages<-c('ggplot2','data.table','knitr','xtable')

> install.packages(packages)
> lapply(packages,library,character.only=T)

Even though the issue is solved I hope it will help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM