Unable to access index for repository: warning in install.packages

I have never been able to install packages using the repository. I have always had to download the tar.gz file and install from a local drive. I have no firewall and cannot find the answer in any of the other questions. Please help me figure this out as I am taking a course in R from Harvard and really need this to start working. Thank you in advance!

#>
 install.packages ("dslabs")
Warning in install.packages :
  unable to access index for repository http://cran.mtu.edu/src/contrib:
  cannot open URL 'http://cran.mtu.edu/src/contrib/PACKAGES'
Installing package into ‘C:/Users/canis/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
  unable to access index for repository http://cran.mtu.edu/src/contrib:
  cannot open URL 'http://cran.mtu.edu/src/contrib/PACKAGES'
Warning in install.packages :
  package ‘dslabs’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Warning in install.packages :
  unable to access index for repository http://cran.mtu.edu/bin/windows/contrib/4.0:
  cannot open URL 'http://cran.mtu.edu/bin/windows/contrib/4.0/PACKAGES'
<-

This seems like a connectivity issue, R is not being able to connect to the CRAN repository you have selected, these are some things to try.

  • Choose a different CRAN repository, RStudios repository is a good choice (http://cran.rstudio.com/) or you could choose one that is geographically closer to you.
  • Disable secure download setting.
  • Check if your internet connection has traffic restrictions of some kind, like a firewall, proxy server, etc. This is usually the case when you are at work or school.

Thank you so much for your help. I changed the repository to http://cran.rstudio.com and deselected "Use secure download method for HTTP". It's a little weird, but when I try to install.packages again, I get the same error as if it's using the same repository as before. Why didn't it change?

#> install.packages ("tidyverse")
Warning in install.packages :
  unable to access index for repository http://cran.mtu.edu/src/contrib:
  cannot open URL 'http://cran.mtu.edu/src/contrib/PACKAGES'
Installing package into ‘C:/Users/canis/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Error in data.frame(name = names(getOption("repos")), host = "", url = as.character(getOption("repos")),  : 
  arguments imply differing number of rows: 0, 1
Warning in install.packages :
  unable to access index for repository http://cran.mtu.edu/src/contrib:
  cannot open URL 'http://cran.mtu.edu/src/contrib/PACKAGES'
Warning in install.packages :
  package ‘tidyverse’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Warning in install.packages :
  unable to access index for repository http://cran.mtu.edu/bin/windows/contrib/4.0:
  cannot open URL 'http://cran.mtu.edu/bin/windows/contrib/4.0/PACKAGES'
<-

I also checked and turned off Windows Defender Firewall and checked if I have a proxy server, which I don't.

And then I connected to my Verizon Hotspot instead of my Spectrum WiFi to see if that was the problem and got the same error. I wish I could fix this. I have to install tidyverse and it requires a lot of other packages to be installed first. I have to download each of them and install them one by one which takes a lot of time. Please help!

Maybe you have hard coded your default package repository in a startup file? Check your Rprofile and Renviron files.

I checked both just now. Thanks for the tip. I found repository setting in RProfile and changed it from @CRAN@ to http://cran.rstudio.com but that didn't work and I used sys.getenv() to check my environment and found no mention of the repository in there. I got the same error with the same weird repository location after changing the repository in RProfile. I have installed other versions of R and this same thing happens. Anybody have any other ideas?

I still think this has to do with a startup file, have you check all of them? They can be in several locations

File Who Controls Level Limitations
.Rprofile User or Admin User or Project None, sourced as R code.
.Renviron User or Admin User or Project Set environment variables only.
Rprofile.site Admin Version of R None, sourced as R code.
Renviron.site Admin Version of R Set environment variables only.

I found it! It wasn't in the R folder at all. It was in my Documents folder and the wrong repository was the only thing in there. Once I changed it, it worked perfectly. OMG, thank you!!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.