29

I am trying to install a package in R, but cannot get around the following error.

What is going on? :(

I am running Fedora 20, R 3.2

 biocLite("monocle")
    BioC_mirror: http://bioconductor.org
    Using Bioconductor version 3.0 (BiocInstaller 1.16.5), R version 3.2.0.
    Installing package(s) 'monocle'
    trying URL 'http://bioconductor.org/packages/3.0/bioc/src/contrib/monocle_1.0.0.tar.gz'
    Content type 'application/x-gzip' length 332309 bytes (324 KB)

    downloaded 324 KB

    installing *source* package ‘monocle’ ...
    R
    inst
    preparing package for lazy loading
    Error in unloadNamespace(package) : 

    namespace ‘plyr’ is imported by ‘reshape2’, ‘ggplot2’, ‘scales’ so cannot be unloaded
    Error in library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : 

    Package ‘plyr’ version 1.8.1 cannot be unloaded
    ERROR: lazy loading failed for package ‘monocle’
    removing ‘/home/user/R/x86_64-redhat-linux-gnu-library/3.2/monocle’
Carmen Sandoval
  • 2,266
  • 5
  • 30
  • 46
  • 1
    It's trying to unload `plyr` but you have other packages loaded that are preventing it from doing so - I'm not exactly sure why it's trying to unload `plyr`, but maybe try unloading `reshape2`, `ggplot2`, and `scales` and see if you can install `monocle`? – blep Sep 24 '15 at 21:56
  • Thanks, how can I unload those other packages? – Carmen Sandoval Sep 24 '15 at 22:05
  • as per http://stackoverflow.com/a/6979989/743568, `detach("package:reshape2", unload=TRUE)` and so on. – blep Sep 24 '15 at 22:26
  • Does it help to start R with the option --vanilla, `R --vanilla` ? Perhaps you have a .Rprofile or .RData file that is causing plyr and other packages to be loaded during installation. – Martin Morgan Sep 25 '15 at 00:51

4 Answers4

38

I resolved this by restarting R.

zach
  • 759
  • 1
  • 9
  • 21
  • 1
    I always restart R before installing new packages to avoid this situation. In RStudio/Windows, the shortcut is CTRL-SHIFT-F10. – Andrew Brēza Jan 06 '21 at 15:29
  • Restarting R worked for me too! It's to do with the order in which the packages are loaded, generally, the most recently loaded package wins. `library(conflicted)` may be helpful in such scenarios, it allows you to choose which function to use https://www.tidyverse.org/blog/2018/06/conflicted/ – landrower Feb 15 '22 at 21:32
9

looks like monocle is trying to unload and install plyr again but it cant because other packages namely ggplot2, scales and reshape2 has dependency on plyr. Please remove these packages using

remove.packages("ggplot2")
remove.packages("reshape2")
remove.packages("scales")

and finally

remove.packages("plyr")

try installing monocle again now.

Monocle does depends on plyr

Depends R (>= 2.7.0), HSMMSingleCell(>= 0.101.5), Biobase, ggplot2 (>= 0.9.3.1), splines, VGAM (>= 0.9-5), igraph (>= 0.7.0), plyr

on monocle homepage http://bioconductor.org/packages/release/bioc/html/monocle.html

Dhawal Kapil
  • 2,584
  • 18
  • 31
  • I wish that would solve it! I've tried it several times, but still get the same error once I go back and try to install Monocle... even if all the packages are uninstalled. – Carmen Sandoval Sep 24 '15 at 22:57
  • is your package `BiocInstaller` out dated..because in my RStudio while installing its printing `trying URL 'http://bioconductor.org/packages/3.1/bioc/bin/windows/contrib/3.2/monocle_1.2.0.zip' Content type 'application/zip' length 756322 bytes (738 KB) downloaded 738 KB` while in your its downloading a previous version of `monocle` – Dhawal Kapil Sep 24 '15 at 23:07
6

I was getting the same error for MASS package.

Below command used to remove that package.

remove.packages("MASS")

Tried freshly below commands and it worked.

install.packages("MASS")
library(MASS)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Nages
  • 763
  • 1
  • 9
  • 12
0

After you uninstall the packages, quit() and restart R again