Unable to access CRAN repository on windows10 with multiple R versions

168 views Asked by At

I am no longer able to install packages for R 3.6.1 (64bit) using CRAN. I have been installing packages on my Windows10 system with CRAN and Rtools 3.5 for years with this R version without any trouble. I think the problem occured after installing R 4.3.0 and Rtools 4.3 on my system. With the same system, when I switch to R 4.3.0 in Rstudio I can install new packages from CRAN without any problem. I uninstalled R 3.6.1, deleted the library paths and reinstalled R 3.6.1 but the problem is still there:

Warning: unable to access index for repository https://cran.rstudio.com/src/contrib: cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'

I have seen a couple of similar problems on stackoverflow but none of the solutions work:

Try disabling “secure download method for HTTP”

Change CRAN repository

When running code:

browseURL("https://cran.rstudio.com/src/contrib/PACKAGES")

a web page opens up in my browser with a list of available packages CRAN link

When running code:

getOption("repos")

I get the following response:

                       CRAN 
"https://cran.rstudio.com/" 
attr(,"RStudio")
[1] TRUE

When running code:

install.packages("ggplot2", repos = "https://cloud.r-project.org")

I get the following response:

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/userName/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
  unable to access index for repository https://cloud.r-project.org/src/contrib:
  cannot open URL 'https://cloud.r-project.org/src/contrib/PACKAGES'
Warning in install.packages :
  package ‘ggplot2’ is not available (for R version 3.6.1)
Warning in install.packages :
  unable to access index for repository https://cloud.r-project.org/bin/windows/contrib/3.6:
  cannot open URL 'https://cloud.r-project.org/bin/windows/contrib/3.6/PACKAGES'

Here is some session info after re-installing R 3.6.1:

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252    LC_MONETARY=French_Canada.1252
[4] LC_NUMERIC=C                   LC_TIME=French_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1

Any help would be appreciated!

2

There are 2 answers

1
Ben Bolker On

The mirror you're trying in the latter code block doesn't seem to exist: the CRAN mirror list lists three Canadian mirrors, one of which is https://mirror.rcg.sfu.ca/mirror/CRAN/ (the .sfu.ca mirror you tried must be defunct). On the other hand, the RStudio mirror (which you're pointing to when you get the https://cran.rstudio.com/src/contrib error) seems to be fine and have a 3.6 directory, see here.

What does

install.packages("ggplot2", repos = "https://cloud.r-project.org")

get you? What is getOption("repos") ?

To test for generic network problems, try

browseURL("https://cran.rstudio.com/src/contrib/PACKAGES")

(Another reason for failing package installs would be a package that requires a newer version of R, but the ggplot2 CRAN page says that R >= 3.3 should be fine.)

0
Arthur Yip On

You should also try installing packages through the R application instead of inside RStudio.