15

I'm new to R and I'm just trying to get through some tutorials.

When I try installing ggplot2, I get this error.

Error in library(ggplot2) : There is no package called 'ggplot2'

I tried these in R and RStudio.

install.packages("ggplot2", dep=T)

install.packages('ggplot2', repos='http://cran.us.r-project.org')

remove.packages("ggplot2")

but I get the error

(Error in remove.packages : there is no package called 'ggplot2')

This is what I get from install.packages("ggplot2")

> install.packages("ggplot2")
Installing package into ‘.../R/win-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = ".../R/win-library/3.4"' is not writable
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/ggplot2_2.2.1.zip'
Content type 'application/zip' length 2784566 bytes (2.7 MB)
downloaded 2.7 MB

package ‘ggplot2’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  cannot remove prior installation of package ‘ggplot2’

The downloaded binary packages are in
    C:...\AppData\Local\temp\RtmpqaGNpr\downloaded_packages

I removed all ggplot2 files manually then tried to install again. Here's my result.

> install.packages("ggplot2")
Installing package into ‘.../R/win-library/3.4’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://ftp.osuosl.org/pub/cran/bin/windows/contrib/3.4/ggplot2_2.2.1.zip'
Content type 'application/zip' length 2784566 bytes (2.7 MB)
downloaded 2.7 MB

package ‘ggplot2’ successfully unpacked and MD5 sums checked
Warning: unable to move temporary installation ‘...\R\win-library\3.4\file26b43a54980\ggplot2’ to ‘...\R\win-library\3.4\ggplot2’

The downloaded binary packages are in
        C:...\AppData\Local\temp\Rtmpq0T9a6\downloaded_packages
> library(ggplot2)
Error in library(ggplot2) : there is no package called ‘ggplot2’
> library("ggplot2")
Error in library("ggplot2") : there is no package called ‘ggplot2’

These code was run using R 3.4.2

MrFlick
  • 195,160
  • 17
  • 277
  • 295
manderson
  • 837
  • 1
  • 6
  • 18
  • 4
    What errors do you get from the `install.packages` lines? That one is probably more relevant. – Gregor Thomas Oct 16 '17 at 15:11
  • 1
    It's better to get `ggplot` from its source. You should install the package `devtools` and then install ggplot using `devtools::install_github("tidyverse/ggplot2")`. Here's a link: https://github.com/tidyverse/ggplot2 – Cris Oct 16 '17 at 15:12
  • `library` doesn't install the package, it just makes it available, first run `install.packages("ggplot2")`, then `library(ggplot2)` – moodymudskipper Oct 16 '17 at 15:14
  • The only other errors I get is that the directory "..R/win-library/3.4" is not writable and do I want to create my own personal library, I click yes. – manderson Oct 16 '17 at 15:21
  • @Cris I tried your suggestion and it went through a ton of installation, but right at the end I got errors (lazy loading failed for package 'ggplot2'), (installation falied: command failed(1)... – manderson Oct 16 '17 at 15:22
  • I should note, this is my work computer. It's a desktop with Windows 7. I did NOT have this problem on my home laptop with Windows 7. – manderson Oct 16 '17 at 15:23
  • @Gregor I updated my post with the result from (install.packages("ggplot2")) – manderson Oct 16 '17 at 15:26
  • @Moody_Mudskipper Yes, I know. After installation, I tried library("ggplot2") and got the (there is no package call 'ggplot2') error. – manderson Oct 16 '17 at 15:27
  • 1
    I had this issue with `purrr` a few days ago, I closed all R sessions I had, removed the existing files manually and installation went fine afterwards – moodymudskipper Oct 16 '17 at 15:33
  • This seems to be a [common-ish](https://stackoverflow.com/questions/46590002/warning-in-install-packages-unable-to-move-temporary-installation) [problem](https://stackoverflow.com/questions/34739681/unable-to-move-temporary-installation-when-installing-dependency-packages-in-r/44256437#44256437) with installing R packages. It seems like the issue is caused by antivirus software. I am using the solution [here](https://stackoverflow.com/questions/34739681/unable-to-move-temporary-installation-when-installing-dependency-packages-in-r/44256437#44256437). – Nick Criswell Oct 16 '17 at 15:36
  • @Moody_Mudskipper I tried what you suggested. I updated my post with my result. – manderson Oct 16 '17 at 15:40
  • where did you delete those files from ? – moodymudskipper Oct 16 '17 at 15:43
  • @NickCriswell Disabling antivirus didn't work for me. – manderson Oct 16 '17 at 15:44
  • `\R\win-library\3.4\ggplot2` was cleaned up ? – moodymudskipper Oct 16 '17 at 15:45
  • you could try to move the files manually, if it's really just an issue of moving, also, have you tried turning it off and on again :)? – moodymudskipper Oct 16 '17 at 15:46
  • @Moody_Mudskipper ggplot2 is being installed into a directory ".../R/win-library/3.4/file26b4f536b86" I deleted that directory and tried again. I also tired to move ggplot2 out of there and into '...R/win-library/3.4/' but get the same error. – manderson Oct 16 '17 at 15:48
  • I also removed R, reinstalled, and tried installing ggplot2 as the first library. Same error. – manderson Oct 16 '17 at 15:57
  • to be sure, other packages install and run fine ? – moodymudskipper Oct 16 '17 at 16:07
  • 1
    you can try to change the default installation folder, check this: https://stackoverflow.com/questions/2698269/how-do-you-change-library-location-in-r – moodymudskipper Oct 16 '17 at 16:09
  • @Moody_Mudskipper That worked. Add as answer. I appreciate that. – manderson Oct 16 '17 at 17:44

4 Answers4

14

Steps

  1. Go To Tools

  2. Install Packages

  3. In Packages Text Box Type ggplot2

  4. Check the checkbox install dependencies

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Santhosh
  • 141
  • 1
  • 4
1

When having this issue I would suggest :

  • try turning it off and on again
  • update R to last version if possible
  • remove manually all the folders related to the relevant package and retry the installation
  • change your default library location : How do you change library location in R?
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
1

Try launching R client directly from command prompt, then issue the instruction: install.packages("ggplot2", lib="C:/Users/YourUser/Documents/R/win-library/3.3")

Renaud
  • 26
  • 4
1

You need to update your R version and do this but you'll need install all packages again:

Tool > Global Options > R version (CHANGE) > Select "Use your machine's default version of R..."

andhherson
  • 37
  • 4