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

20
  • 4
    What errors do you get from the install.packages lines? That one is probably more relevant. Oct 16, 2017 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: github.com/tidyverse/ggplot2
    – Cris
    Oct 16, 2017 at 15:12
  • 1
    library doesn't install the package, it just makes it available, first run install.packages("ggplot2"), then library(ggplot2) Oct 16, 2017 at 15:14
  • 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 Oct 16, 2017 at 15:33
  • 1
    you can try to change the default installation folder, check this: stackoverflow.com/questions/2698269/… Oct 16, 2017 at 16:09

4 Answers 4

14

Steps

  1. Go To Tools

  2. Install Packages

  3. In Packages Text Box Type ggplot2

  4. Check the checkbox install dependencies

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?
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")

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.