Unable to install R Packages through R Console and RStudio

Hello.

I can't install any packages in R using both R Console and RStudio. I'm trying to install tm package, and received the warning messages.

Installing package into ‘/R/win-library/4.1’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Warning: failed to download mirrors file (cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'); using local file 'C:/PROGRA~1/R/R-41~1.1/doc/CRAN_mirrors.csv'
Warning: 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: unable to access index for repository https://cloud.r-project.org/bin/windows/contrib/4.1:
  cannot open URL 'https://cloud.r-project.org/bin/windows/contrib/4.1/PACKAGES'
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
  InternetOpenUrl failed: ''
2: package ‘tm’ 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

I've unchecked the "User secure download method for HTTP" in RStudio (as suggested in this link), but it's still the same. RStudio is allowed in my laptop's firewall settings by default, but I just added R for Windows terminal front-end in the allowed apps. Still I get the same error.

Session info

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

I don't know what to do next. Many thanks.

Regards

stepping away from Rstudio and R in the terminal for a moment, lets verify the following ...
if you paste the url into your browser does it succeed in downloading the csv?
[https://cran.r-project.org/CRAN_mirrors.csv]

Hello! Thanks for your suggestion.

I tried doing that in two ways. (1) Just by reading the CSV file using read.csv function , and (2) using download.file function to download the file into my default working directory (Documents).

Using the first method, I got the following:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : InternetOpenUrl failed: ''

While using second method, I got:

Error in download.file("https://cran.r-project.org/CRAN_mirrors.csv",  : 
  cannot open destfile '~/Documents', reason 'Permission denied'

Is there some sort of a restriction that has been set in my laptop? Looks like it. Thanks.

I'm thinking its a general internet access issue you have. Therefore I really think it would be worthwhile of you to also attempt to do it in your web browser as I suggested...

Is this a personal laptop, or something set up by an organisation ?

I did it through the browser, but I was able to download the CRAN_mirrors.csv. It's a work laptop, but I've been using RStudio since last year without these errors until last night. Tried uninstalling both R and RStudio to no luck. So far, I haven't heard of any restrictions updates, but we shouldn't be getting such. Internet's pretty okay as there are no restricted sites.

ok, if you can get it through your browser there would seem to be hope. lets go back to download.file
The error read to me like you may have mispecified destfile ? do you get the same error when you try

download.file("https://cran.r-project.org/CRAN_mirrors.csv",destfile = "cmir.csv")

also what results for you when you do :

getOption("download.file.method")

Yup. Same error as with download.file("https://cran.r-project.org/CRAN_mirrors.csv",destfile = "cmir.csv")

trying URL 'https://cran.r-project.org/CRAN_mirrors.csv'
Error in download.file("https://cran.r-project.org/CRAN_mirrors.csv",  : 
  cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'
In addition: Warning message:
In download.file("https://cran.r-project.org/CRAN_mirrors.csv",  :
  InternetOpenUrl failed: '"'

For getOption("download.file.method"), it returns NULL.

Here you can try setting some explicit methods (though I think on windows download.file would default to wininet anyway)

options("download.file.method"="wininet")
download.file("https://cran.r-project.org/CRAN_mirrors.csv",destfile = "cmir.csv")
options("download.file.method"="libcurl")
download.file("https://cran.r-project.org/CRAN_mirrors.csv",destfile = "cmir.csv")

I might also try package RCurl to see if it works or if theres any good error info:


install.packages("RCurl")
library(RCurl)
getURLContent("https://cran.r-project.org/CRAN_mirrors.csv")
1 Like

Setting the download.file.method to libcurl fixed it for me. I can now install the needed packages. Many thanks to you!

It's just kinda sudden that I'm getting these issues. But I'm good for now. I truly appreciate your effort on this. :smiley:

1 Like

You're welcome, glad I could help

1 Like

This topic was automatically closed 7 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.