75

I am unable to install packages through latest version of RStudio and R Version.3.1.1. Kindly help. I got the error as mentioned below:

Example:
Warning in install.packages :
  InternetOpenUrl failed: ''
Warning in install.packages :
  InternetOpenUrl failed: ''
Warning in install.packages :
  unable to access index for repository http://cran.rstudio.com/bin/windows/contrib/3.1
Installing package into ‘C:/Users/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
  InternetOpenUrl failed: ''
Warning in install.packages :
  InternetOpenUrl failed: ''
Warning in install.packages :
  unable to access index for repository http://cran.rstudio.com/bin/windows/contrib/3.1
Warning in install.packages :
  package ‘reshape’ is not available (for R version 3.1.1)
manjula sridhar
  • 751
  • 1
  • 6
  • 6
  • Firewall/proxy issue? Did it work before? –  Sep 01 '14 at 06:34
  • 1
    Response on RStudio support site: https://support.rstudio.com/hc/communities/public/questions/200522573-Can-t-install-packages – Andrie Jan 13 '15 at 14:39
  • I had this problem too. The solution was to use another mirror. – CoderGuy123 Jul 06 '15 at 00:48
  • Following these steps solved my issue: https://github.com/ContinuumIO/anaconda-issues/issues/4421#issuecomment-327033866 In Terminal, run `conda install libssh2` then `conda install krb5` – Zack Katz Sep 27 '17 at 19:40
  • I tried everything, however only reinstalling R and Rstudio worked for me. I later installed it in Anaconda. – rishi jain May 16 '20 at 17:21

9 Answers9

157

Not 100% certain that you have the same problem, but I found out the hard way that my job blocks each mirror site option that was offered and I was getting errors like this:

Installing package into ‘/usr/lib64/R/library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in download.file(url, destfile = f, quiet = TRUE) : 
  unsupported URL scheme
Warning: unable to access index for repository https://rweb.crmda.ku.edu/cran/src/contrib
Warning message:
package ‘ggplot2’ is not available (for R version 3.2.2)

Workaround (I am using CentOS)...

install.packages('package_name', dependencies=TRUE, repos='http://cran.rstudio.com/')

I hope this saves someone hours of frustration.

cer
  • 1,961
  • 2
  • 17
  • 26
  • 2
    Strange for me as I was able to install packages no problem until this morning... But this worked immediately. – Cayce K Dec 16 '15 at 15:50
  • also, check that the ```download.file.method``` isn't set in your RProfile. https://support.rstudio.com/hc/en-us/articles/206827897-Secure-Package-Downloads-for-R – polka May 31 '17 at 18:49
  • 3
    Also note that you may get `unable to access index for repository` if trying to use `https` instead of `http` – ionox0 Jul 02 '18 at 14:26
  • how does install.packages() method work when we specify repos as `repos='http://cran.rstudio.com/')` instead of `http://cran.us.r-project.org` – Regressor Feb 24 '20 at 16:56
  • I am really not sure, but you can certainly try it out to see if it does -- let me know if it works @Regressor. – cer Mar 03 '20 at 14:12
76

I think this is the "set it and forget it" solution:

options(repos='http://cran.rstudio.com/')

Note that this isn't https. I was on a Linux machine, ssh'ing in. If I used https, it didn't work.

rbatt
  • 4,677
  • 4
  • 23
  • 41
  • 2
    My problem went away from repos='https://cran.rstudio.com/' to ...http... – Kemin Zhou Apr 02 '16 at 00:37
  • 3
    Tools -> Global Options -> Packages --> I unchecked use secure download method for HTTP, it worked, all issues disappeared, R also provides that option, you need to select "other mirrors" and select 0 Clould and hit OK – Ravi M Patel Sep 19 '18 at 11:57
  • Worked like a charm.... I was trying to use HTTPS and it was giving me an error is not valid for rstudio3.1 and it solved the problem thanks.... – Skizo-ozᴉʞS ツ Dec 11 '18 at 23:52
  • Didn't work for me on Linux Mint 19 with RStudio 1.2 and R 3.4.4, what am I doing wrong? It always returns: `Installing package into ‘/home/leon/R/x86_64-pc-linux-gnu-library/3.4’ (as ‘lib’ is unspecified) Warning in install.packages : package ‘pacman’ is not available (for R version 3.4.4)` – Leo Jul 11 '19 at 22:58
7

As @Pascal said, it is likely that you encounter problem with the firewall or/and proxy issue. As a first step, go through FAQ on the CRAN web page. After that, try to flag R with --internet2.

Sometimes it could be useful to check global options in R studio and uncheck "Use Internet Explorer library/proxy for HTTP". Tools -> Global Options -> Packages and unchecking the "Use Internet Explorer library/proxy for HTTP" option.

Hope this helps.

Newbie_R
  • 655
  • 7
  • 22
6

Based on answers from the community, there appear to be several ways that might solve this:

  1. From the official FAQ and support forums and this answer, you may have have a firewall or proxy issue that is blocking RStudio from connecting to the internet:
  • Disable any firewalls
  • Tools -> Global Options -> Packages and unchecking the "Use Internet Explorer library/proxy for HTTP" option and restart R (#1, #2, #3)
  • Flag R with --internet2
  • On CentOS it was suggested to try the following: install.packages('package_name', dependencies=TRUE, repos='http://cran.rstudio.com/')
  1. Several answers suggest using an alternate mirror (#1, #2, #3):
  • Preferences > General > Default working directory > Browse and switch your mirror from local/global (whichever is unchecked)
  1. On Windows you can start the application with http_proxy=http://host:port/:
  • "C:\Program Files\RStudio\bin\rstudio.exe" http_proxy=http://host:port/
  1. Shut down and restart. Needed after many of the above operations, and suggested standalone.
mirh
  • 514
  • 8
  • 14
Tas
  • 7,023
  • 3
  • 36
  • 51
  • One more: this error occurs if there is no more space on the harddrive (Windows) – mts Jan 12 '16 at 22:40
  • I don't see the option "Use Internet Explorer library/proxy for HTTP", only "Enable packages pane" and "Use secure download method for HTTP". What should I do? – Leo Jul 11 '19 at 22:47
3

My solution that worked was to open R studio options and select global miror (the field was empty before) and the error went away.

userJT
  • 11,486
  • 20
  • 77
  • 88
3

Please check the following to be able to install new packages:

1- In Tools -> Global Options -> Packages, uncheck the "Use Internet Explorer library/proxy for HTTP" option,

2- In Tools -> Global Options -> Packages, change the CRAN mirror to "0- Cloud - Rstudio, automatic redirection to servers worldwide"

3- Restart Rstudio.

4- Have fun!

Mohammad
  • 1,006
  • 2
  • 15
  • 29
1

If you are on Windows, try this:

"C:\Program Files\RStudio\bin\rstudio.exe" http_proxy=http://host:port/

Steve Pitchers
  • 7,088
  • 5
  • 41
  • 41
1

Most of the time @cer solution works but if in case its not working then try installing it in base R (NOT in R studio). As R studio runs base R executable in background so new package will be available in R studio as well. [my experience in macOS]

abhiieor
  • 3,132
  • 4
  • 30
  • 47
0

What worked for me:

Preferences-General-Default working directory-Browse Switch from global to local mirror

Working on a Mac. 10.10.3

Clayton
  • 11