3

I have been trying to install the ggplot2 package in R and this is the warning I have been getting:

Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open the connection

In addition: Warning messages:

1: In download.file(url, destfile, method, mode = "wb", ...) : downloaded length 1040720 != reported length 1152839

2: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file

3: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'plyr/DESCRIPTION', probable reason 'No such file or directory'

It might be helpful to note that I am using the version 3.1.1. Could you please help me understand what went wrong and how I could resolve this?

Thank you in advance.

JohnK
  • 1,019
  • 3
  • 14
  • 30
  • what command did you enter that generated that error? – GSee Sep 28 '14 at 14:57
  • @GSee install.packages("ggplot2"), that is all. – JohnK Sep 28 '14 at 15:02
  • 1
    Try `install.packages("ggplot2", repos="http://cran.us.r-project.org")` or `install.packages("ggplot2", repos="http://cran.rstudio.org")` – GSee Sep 28 '14 at 15:03
  • What is the output of `getOption("repos")`? – GSee Sep 28 '14 at 15:03
  • @Gsee The output is CRAN CRANextra "http://www.freestatistics.org/cran" "http://www.stats.ox.ac.uk/pub/RWin" – JohnK Sep 28 '14 at 15:05
  • Well, that's your problem. How did you set that option? It should have http:// as part of the addresses – GSee Sep 28 '14 at 15:08
  • @Gsee I do not think I did it myself, could you tell me how to fix it? – JohnK Sep 28 '14 at 15:09
  • you could do `options(repos=c(CRAN="@CRAN@"))`. If you start a fresh R session, does `getOption("repos")` return the same thing? If so, that suggests it's being set in your .Rprofile or Rprofile.site – GSee Sep 28 '14 at 15:12
  • @GSee Now I am getting CRAN CRANextra "@CRAN@" "http://www.stats.ox.ac.uk/pub/RWin" – JohnK Sep 28 '14 at 15:13
  • @Gsee thank you. If you would like to post all your comments as an answer so I can mark it as the correct one, please do so. – JohnK Sep 28 '14 at 15:14
  • Can help me with this related post please? https://stackoverflow.com/questions/61200536/r-unable-to-install-r-packages-cannot-open-the-connection – The Great Apr 14 '20 at 08:12

1 Answers1

7

From the comments we discovered that somehow your repos option had been set to a bad value.

install.packages has an argument called repos that can be used to specify where to find the package that you'd like to install. If you specify a valid value, it should just work. e.g. you shouldn't get the error if you do this: install.packages("ggplot2", repos="http://cran.us.r-project.org")

If you do not provide a value, it will look at the repos option. See getOption("repos") to see what is set. In your case it was

                     CRAN                 CRANextra 
"freestatistics.org/cran" "stats.ox.ac.uk/pub/RWin" 

neither of which are valid URLs.

You can change the value of the repos option like this

options(repos=c(CRAN="@CRAN@", 
                CRANextra="http://www.stats.ox.ac.uk/pub/RWin"))
GSee
  • 48,880
  • 13
  • 125
  • 145
  • see also the `repos` section of `?options` as well as `?setRepositories` – GSee Sep 28 '14 at 15:27
  • Can help me with this related post please? It is same as the above but my CRAN is already US. site. But still I get this error https://stackoverflow.com/questions/61200536/r-unable-to-install-r-packages-cannot-open-the-connection – The Great Apr 14 '20 at 07:45