问题
I'm trying to run a script that worked well in the past few days, but has been causing me much grief recently.
When I try to load the caret library, it says that there is a problem with ggplot2. Here is the output:
> library(caret)
Loading required package: lattice
Loading required package: ggplot2
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
object 'pkgInfo' not found
Error: package ‘ggplot2’ could not be loaded
I have no clue what pkgInfo is. Other StackOverflow questions answers to this problem are that that's from not using quotes in your code making R think that it's looking for an object named pkgInfo. But in this case, the error is coming from inside...
...the source code of ggplot2. (maybe, I don't know, it's not my code directly causing the error I know) I've ran install.packages("ggplot", dep = TRUE)
and it fixed the problem for now, but I want a longer solution. I'm pretty sure I tried that yesterday and left me to still need to fix it today. I'd also like an explanation if y'all can provide so I can prevent this in the future. Thanks!
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lattice_0.20-35
loaded via a namespace (and not attached):
[1] compiler_3.5.1 backports_1.1.2 magrittr_1.5 rprojroot_1.3-2 htmltools_0.3.6 tools_3.5.1 yaml_2.2.0
[8] Rcpp_0.12.18 stringi_1.1.7 rmarkdown_1.10 grid_3.5.1 knitr_1.20 stringr_1.3.1 digest_0.6.15
[15] evaluate_0.11
回答1:
I think it is caret, since caret is wrapper to a lot R package, caret does not use the traditional package dependency process in R, if it did caret would require the install of a lot of packages.
https://cran.r-project.org/web/packages/caret/vignettes/caret.html
You can force it by
install.packages("caret", dependencies = c("Depends", "Suggests"))
The following slide deck (by Max Kuhn, and Zachary Deane-Mayer) explains it a lot better than I could.
https://www.slideshare.net/sermakarevich/odscbos2015maxkhun-150601094910lva1app6892
In the package DESCRIPTION The Imports section lists packages that may be loaded at run time. Suggests are packages that may be used but are not required, and Depends are packages that are loaded as soon as caret is loaded
ggplot2 is listed under the Depends section in caret
https://github.com/topepo/caret/blob/master/pkg/caret/DESCRIPTION
回答2:
I am sorry for posting misleading info, a red herring.
My working directory for R is in my Documents folder. My Documents folder is synced to my google drive, and I noticed a few days ago that google drive was working very hard, sucking up some resources in the background. I saw that a lot of the files it was trying to sync was in the win-library directory for R. I, not knowing how to truly stop the syncing of a subdirectory, deleted the directory from my google drive expecting it to stop messing with my R on my laptop.
Instead, Google started messing with my R files even more. Now that I've stopped syncing my Documents folder with Google Drive, everything is running smoothly.
来源:https://stackoverflow.com/questions/51967560/object-pkginfo-not-found-r