Help needed: unable to install any package in Rstudio

I am unable to install any package in R studio. The problem really troubles me these days.

install.packages("openxlsx")
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open URL 'http://cran.rstudio.com/src/contrib/PACKAGES'

Warning messages:
1: In download.file(mirrors_csv_url, destfile = mirrors_csv, quiet = TRUE) :
URL 'http://cran.r-project.org/CRAN_mirrors.csv': status was 'Couldn't resolve host name'
2: In download.file(mirrors_csv_url, destfile = mirrors_csv, quiet = TRUE) :
URL 'http://cran.r-project.org/CRAN_mirrors.csv': status was 'Couldn't resolve host name'

The full warning is below (sry I don't know how to quote the code). I've adjusted the settings in 'packages' as instructed in other posts, but it doesn't work.

Any help will be really appreciated!
Thanks in advance!

Try opening your browser and directing it to

https://cran.rstudio.com/src/contrib/PACKAGES

If you get an error trying that, there is some setting in your general web access that is blocking the website. Are you behind a corporate firewall?

I don't have an error when entering the site, and I've checked that I had already turned off the firewall in the system setting of my Mac. I'm not behind a corporate firewall.

Can you read this data set from RStudio?

TestDF <- read.csv("https://sebastiansauer.github.io/data/TeachingRatings.csv")

TestDF <- read.csv("https://sebastiansauer.github.io/data/TeachingRatings.csv")
Error in file(file, "rt") :
cannot open the connection to 'https://sebastiansauer.github.io/data/TeachingRatings.csv'
In addition: Warning message:
In file(file, "rt") :
URL 'https://sebastiansauer.github.io/data/TeachingRatings.csv': status was 'Couldn't resolve host name'

I cannot read this data =(

I would try resetting RStudio. If you haven't tried simply restarting RStudio, try that first. If that does not work, shutdown RStudio and run this command in the terminal.

mv ~/.local/share/rstudio ~/.local/share/rstudio-backup

Then restart RStudio.

I've already restarted Rstudio for several times, but nothing changed.

I run the command in the terminal, and it shows:
(base) fanxuehans-MacBook-Pro:1 fanxuehan$ mv ~/.local/share/rstudio ~/.local/share/rstudio-backup
mv: rename /Users/fanxuehan/.local/share/rstudio to /Users/fanxuehan/.local/share/rstudio-backup/rstudio: Directory not empty

When I install packages after restarting Rstudio, it still shows:

install.packages("shiny")
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open URL 'http://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.4:
cannot open URL 'http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.4/PACKAGES'

It looks like the mv command did not work. I don't see anything wrong with what you typed. Can you navigate to the /Users/fanxuehan/.local/share/ folder and rename the rstudio file to rstudio-backup?

I have to stop for tonight, it is late here.

Thank you so much! I'll try this later.
Good night :smiley:

Seems like you cannot download any any from within R. What is the output of this?

getOption("download.file.method")
getOption("url.method")

Do you have any custom settings in your ~/.Rprofile file?

It shows:

getOption("download.file.method")
NULL
getOption("url.method")
NULL

I've navigate to the /Users/fanxuehan/.local/share/ folder, but sorry that I'm not so sure about how to rename the rstudio file to rstudio-backup TT

It is unlikely that this has much to do with RStudio. It is an issue with R itself, not Rstudio.

First, I would turn on the "Use secure download method for HTTP" in the RStudio config.

Second, check that you have the http_proxy or https_proxy or HTTP_PROXY or HTTPS_PROXY environment variables set.

After that, try if this works.

curlGetHeaders("https://cran.rstudio.com")