unable to install package in R Studio - Warning: unable to access index for repository...

Team

I am unable to install any package from my R Studio. Please find below errors while installing the package.

install.packages("ggplot2")
Warning in install.packages :
 unable to access index for repository https://cran.rstudio.com/src/contrib:
 cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Installing package into ‘C:/Users/Saravana/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
 unable to access index for repository https://cran.rstudio.com/src/contrib:
 cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
 package ‘ggplot2’ is not available (for R version 3.5.1)
Warning in install.packages :
 unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.5:
 cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/PACKAGES'

kindly help me out.

Thanks in advance

Hi,

See this answer to a similar question (the advice applies for cases where you're getting unable to access index for repository for multiple packages):

1 Like

Hi
Thanks for your reply.

I was turn off my antivirus and I have followed your instruction but I couldnt proceed further.

PFB.

cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/PACKAGES'
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
> install.packages("C:/Users/Saravana/Downloads/sparklyr_0.9.1.tar.gz", repos = NULL, type = "source")
Installing package into ‘C:/Users/Saravana/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
ERROR: dependencies 'assertthat', 'base64enc', 'broom', 'config', 'DBI', 'dplyr', 'dbplyr', 'digest', 'httr', 'jsonlite', 'lazyeval', 'openssl', 'r2d3', 'rappdirs', 'rlang', 'rprojroot', 'rstudioapi', 'shiny', 'withr', 'xml2', 'tibble', 'tidyr', 'purrr', 'forge' are not available for package 'sparklyr'
* removing 'C:/Users/Saravana/Documents/R/win-library/3.5/sparklyr'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘C:/Users/Saravana/Downloads/sparklyr_0.9.1.tar.gz’ had non-zero exit status

please help me out.

Thanks in advance.

Hmm, is it possible you're behind a firewall? Those packages it lists are dependencies for sparklyr, when you run regular install.packages() not from source, you can just put the dependencies = TRUE, but obviously that doesn't work for installing from local.

Can you download the httr package? That might let us explore whether or not you can access the internet from R.

Still I am facing the same issue.

install.packages("httr")
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open destfile 'C:\Users\Saravana\AppData\Local\Temp\Rtmp6JHOS1\file15982ac55444', reason 'No such file or directory'
Error in install.packages : cannot open the connection
> install.packages("C:/Users/Saravana/Downloads/sparklyr_0.9.1.tar.gz", repos = NULL, type = "source")
Installing package into ‘C:/Users/Saravana/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
ERROR: dependencies 'assertthat', 'base64enc', 'broom', 'config', 'DBI', 'dplyr', 'dbplyr', 'digest', 'httr', 'jsonlite', 'lazyeval', 'openssl', 'r2d3', 'rappdirs', 'rlang', 'rprojroot', 'rstudioapi', 'shiny', 'withr', 'xml2', 'tibble', 'tidyr', 'purrr', 'forge' are not available for package 'sparklyr'
* removing 'C:/Users/Saravana/Documents/R/win-library/3.5/sparklyr'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘C:/Users/Saravana/Downloads/sparklyr_0.9.1.tar.gz’ had non-zero exit status
Error in gzfile(file, mode) : cannot open the connection
In addition: Warning message:
In gzfile(file, mode) :
  cannot open compressed file 'C:\Users\Saravana\AppData\Local\Temp\Rtmp6JHOS1/libloc_185_a25398df.rds', probable reason 'No such file or directory'
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open destfile 'C:\Users\Saravana\AppData\Local\Temp\Rtmp6JHOS1\file159861a811a0', reason 'No such file or directory'
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open destfile 'C:\Users\Saravana\AppData\Local\Temp\Rtmp6JHOS1\file15981f4558b7', reason 'No such file or directory'
Error in gzfile(file, mode) : cannot open the connection

the same package I can able to run in R console.

PFB for the log.

> install.packages("httr")
Installing package into ‘C:/Users/Saravana/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
also installing the dependencies ‘jsonlite’, ‘mime’, ‘curl’, ‘openssl’, ‘R6’

trying URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/jsonlite_1.5.zip'
Error in download.file(url, destfile, method, mode = "wb", ...) : 
  cannot open URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/jsonlite_1.5.zip'
In addition: Warning message:
In download.file(url, destfile, method, mode = "wb", ...) :
  InternetOpenUrl failed: 'A connection with the server could not be established'
Warning in download.packages(pkgs, destdir = tmpd, available = available,  :
  download of package ‘jsonlite’ failed
trying URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/mime_0.6.zip'
Content type 'application/zip' length 47811 bytes (46 KB)
downloaded 46 KB

trying URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/curl_3.2.zip'
Content type 'application/zip' length 2986361 bytes (2.8 MB)
downloaded 2.8 MB

trying URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/openssl_1.0.2.zip'
Error in download.file(url, destfile, method, mode = "wb", ...) : 
  cannot open URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/openssl_1.0.2.zip'
In addition: Warning message:
In download.file(url, destfile, method, mode = "wb", ...) :
  InternetOpenUrl failed: 'A connection with the server could not be established'
Warning in download.packages(pkgs, destdir = tmpd, available = available,  :
  download of package ‘openssl’ failed
trying URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/R6_2.3.0.zip'
Content type 'application/zip' length 57250 bytes (55 KB)
downloaded 55 KB

trying URL 'https://ftp.iitm.ac.in/cran/bin/windows/contrib/3.5/httr_1.3.1.zip'
Content type 'application/zip' length 482200 bytes (470 KB)
downloaded 470 KB

package ‘mime’ successfully unpacked and MD5 sums checked
package ‘curl’ successfully unpacked and MD5 sums checked
package ‘R6’ successfully unpacked and MD5 sums checked
package ‘httr’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\Saravana\AppData\Local\Temp\Rtmpollh6D\downloaded_packages

Oh, that's good! It looks like you're able to connect to a different CRAN mirror. You can change that setting in RStudio, too. I'm not at my computer at the moment, but you should also be able to access the successfully downloaded packages in RStudio, since it's just an IDE on top of R.

1 Like

Hi Mara

once you back to your computer, can you please help me out. I dont know..what settings needs to done? I tried my level best to changed settings, but still I couldnt resolved the issue.

Thanks in advance.

See the pictorial here:

Hi Mara

I couldnt find the secondary source. Please find the attached screenshot for your reference.

please do the needful.

You mean the link doesn't work? What happens when you click on "Change…"?

no.. I am trying to follow your instructions but i could find any secondary Repo...there only I have to enter the name and url..but I couldnt find anything..

please do the needful.

In that case, just enter the URL of the CRAN mirror that worked:

https://ftp.iitm.ac.in/cran/

I had the same problem, very annoying really, thats how i solved:
tools/installpackages/installtolibrary/(change_it_to)c:programfiles/r/r-351/library

I think this is not related to the same issue, the OP has problems accessing CRAN repositories and this answer has to do with .libPaths

This works for me. Thanks

In R studio go at: Tools > Global Options > packages > uncheck the option: "Use secure download for HTTP". Only check the options: "Enable packages pane" and "Use Internet Explorer library/proxy for HTTP"

10 Likes

Hi There!

Thanks dear!
Your information was of great help and it worked for me !

2 Likes

I had the same issue when I installed "0-Cloud" CRAN mirror. I uninstalled it, and installed a mirror based on country, for me it was USA - Indiana University, and it works.

Hi!
Your help was appreciated and it really worked for me !! Thanks a lot;)