简体   繁体   中英

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

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’
> 

Steps

  1. Go To Tools

  2. Install Packages

  3. In Packages Text Box Type ggplot2

  4. Check the checkbox install dependencies

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?

尝试直接从命令提示符启动 R 客户端,然后发出指令: install.packages("ggplot2", lib="C:/Users/YourUser/Documents/R/win-library/3.3")

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

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