0

I'm having trouble installing the ggplot2 package in R. According to R-studio, I have the latest version installed; this is what it says when R studio first loads:

R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

I'm assuming this means I'm using the correct version. But then, when I try to install the ggplot2 package using the install.packages("ggplot2") command, I get the following error (had to post in pastebin because it contained links):

http://pastebin.com/deqn0vFw

It appears to be some kind of error with my internet connection (not sure how to fix it, googling didn't seem to give a concrete answer). After I got that error, I went ahead and just tried downloading the .zip file for ggplot2 from the official CRAN website. Then, in R-Studio I went ahead and went to Tools>Install Packages and just installed it from the .zip. Then, in the console it said

> install.packages("C:/Users/ralei/Downloads/ggplot2_1.0.1.zip", repos = NULL, type = "win.binary")
Installing package into ‘C:/Users/ralei/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
package ‘ggplot2’ successfully unpacked and MD5 sums checked

But then when I call the ggplot2 library using the library(ggplot2) I get the error:

> library(ggplot2)
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 

there is no package called ‘digest’

After going ahead and installing the 'digest' package (again through the CRAN website), I got another error when I tried to load ggplot2.

 > library(ggplot2)
 Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
   there is no package called ‘gtable’
 Error: package or namespace load failed for ‘ggplot2’

Can anybody explain to me what I'm doing wrong?

Thanks.

EDIT: This was marked as a duplicate to a "what to do if your package isn't available" error question but I don't see how my question is a duplicate of that -- I'm not getting the "package is unavailable" error since I can install it manually, but it seems that when I install ggplot2, the installation doesn't seem to 'stick'.

lmo
  • 37,904
  • 9
  • 56
  • 69
Raleigh L.
  • 599
  • 2
  • 13
  • 18
  • 3
    Well, you need all packages in ggplot2's dependency/imports tree. Please include the error message as text in your question. (If SO doesn't let you do this, due to links to the CRAN mirror, just remove these links.) – Roland Sep 21 '15 at 08:25
  • 1
    You could try `require(ggplot2)` that works sometimes – erasmortg Sep 21 '15 at 08:27
  • @erasmortg I tried that and got the error : `> require(ggplot2)` `Loading required package: ggplot2` `Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called ‘gtable’` Do I just go and install gtable and resolve it? – Raleigh L. Sep 21 '15 at 08:41
  • 1
    Your first step should be to try a different CRAN mirror for installation. Otherwise, you really have to manually install all dependencies and imports as well as their dependencies ... So, yes, you have to install the gtable package. – Roland Sep 21 '15 at 09:10
  • Thanks for the reply, @Roland. I tried installing all of the dependencies manually but still had an issue later on when I tried to call qplot(), which is a ggplot2 function. It said that the function was not available, even though I had installed ggplot2 and all of it's dependencies that were listed (one of the other commenters had them). I'm really quite a lost of what is happening right now. I even tried uninstalling R and then reinstalling and I'm still getting the error message that it can't connect to the CRAN repository. – Raleigh L. Sep 26 '15 at 06:08

1 Answers1

6

Try using running this code..

install.packages('ggplot2',dependencies = TRUE)

If you are still facing problem than make sure installing the dependencies individually ("plyr","digest","gtable","reshape2","scales","proto","MASS" etc) from the following website https://cran.rstudio.com/ and check whether the install file unpacked in the directory C:\Users\Sahidul.Islam\Documents\R\win-library\3.2. enter image description here

If still not working than upgrade R software and all packages (package can be upgrade by clicking the "Packages"+"upgrade packages..." inside the menu bar in R Software.

  • Hey, thanks for the reply. I tried running your code and got the warning message: `'ggplot2' is not available (for R version 3.2.2)` – Raleigh L. Sep 26 '15 at 06:01
  • Then I tried doing the thing you suggested where I download each of the packages and install them. For some reason even though it did install in that folder, I still couldn't load the packages. I tried calling qplot() which is is a function in ggplot2 (I did this after installing ggplot2 and all of the dependencies listed) and for some reason it said the function still didn't exist. – Raleigh L. Sep 26 '15 at 06:04
  • I then tried uninstalling R and R studio and then reinstalling and then running your code, and it still didn't work. It fails again with the error: `Warning: unable to access index for repository https://cran.cnr.Berkeley.edu/src/contrib` – Raleigh L. Sep 26 '15 at 06:06
  • 1
    Sorry for late response. Please see FAQ 2.19 and others (https://cran.r-project.org/bin/windows/base/rw-FAQ.html#The-Internet-download-functions-fail_002e). Also search for "unable to connect to 'cran.r-project.org' on port 80" (http://rseek.org/). – Md. Sahidul Islam Oct 03 '15 at 10:39