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!

1 Like

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")

Something seems wrong, but I don't know how to fix it.
Maybe there's something wrong with my code (?

(base) fanxuehan@fanxuehans-MacBook-Pro ~ % lsof -n -P -i TCP -s TCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rapportd 574 fanxuehan 4u IPv4 0x886b7e439c98e757 0t0 TCP *:63573 (LISTEN)
rapportd 574 fanxuehan 8u IPv6 0x886b7e4d2e681a5f 0t0 TCP *:63573 (LISTEN)
ControlCe 627 fanxuehan 5u IPv4 0x886b7e4397d4fd77 0t0 TCP *:7000 (LISTEN)
ControlCe 627 fanxuehan 6u IPv6 0x886b7e485e709a5f 0t0 TCP *:7000 (LISTEN)
ControlCe 627 fanxuehan 7u IPv4 0x886b7e4397d4f267 0t0 TCP *:5000 (LISTEN)
ControlCe 627 fanxuehan 8u IPv6 0x886b7e485e70a25f 0t0 TCP *:5000 (LISTEN)
falemonlf 912 fanxuehan 7u IPv4 0x886b7e439c99c887 0t0 TCP 127.0.0.1:10793 (LISTEN)
falemonht 915 fanxuehan 3u IPv4 0x886b7e439c990887 0t0 TCP 127.0.0.1:10792 (LISTEN)
Microsoft 1518 fanxuehan 14u IPv6 0x886b7e4d2e68225f 0t0 TCP [::1]:42050 (LISTEN)
wpsclouds 7745 fanxuehan 210u IPv6 0x886b7e4d2e68325f 0t0 TCP *:62853 (LISTEN)
rsession- 8211 fanxuehan 5u IPv4 0x886b7e439c9af267 0t0 TCP 127.0.0.1:26279 (LISTEN)
rsession- 8211 fanxuehan 23u IPv4 0x886b7e43a1d89397 0t0 TCP 127.0.0.1:30300 (LISTEN)

(base) fanxuehan@fanxuehans-MacBook-Pro ~ % export http_proxy=http://127.0.0.1:10793
(base) fanxuehan@fanxuehans-MacBook-Pro ~ % curlGetHeaders("https://cran.rstudio.com")
zsh: unknown file attribute: h

curlGetHeaders() is an R function, run it from R.

Also, did you set a proxy? Is it working properly? Can you try it without the proxy?

I guess the proxy is working properly...?

(base) fanxuehan@fanxuehans-MacBook-Pro ~ % export
CONDA_DEFAULT_ENV=base
CONDA_EXE=/opt/anaconda3/bin/conda
CONDA_PREFIX=/opt/anaconda3
CONDA_PROMPT_MODIFIER='(base) '
CONDA_PYTHON_EXE=/opt/anaconda3/bin/python
CONDA_SHLVL=1
DISPLAY=/private/tmp/com.apple.launchd.c6zcg7F6E8/org.xquartz:0
GSETTINGS_SCHEMA_DIR=/opt/anaconda3/share/glib-2.0/schemas
GSETTINGS_SCHEMA_DIR_CONDA_BACKUP=''
HOME=/Users/fanxuehan
LANG=zh_CN.UTF-8
LOGNAME=fanxuehan
LaunchInstanceID=2BE2D849-C8C6-4060-81F9-5692FDBA1442
OLDPWD=/Users/fanxuehan
PATH=/opt/anaconda3/bin:/opt/anaconda3/condabin:/Users/fanxuehan/Library/Caches/activestate/bin:/Users/fanxuehan/.local/ActiveState/StateTool/release/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
PWD=/Users/fanxuehan
SECURITYSESSIONID=186b4
SHELL=/bin/zsh
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.O7mXEae6nF/Listeners
TERM=xterm-256color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=447
TERM_SESSION_ID=F8344802-EE32-4C97-976C-E559EBD70FA9
TMPDIR=/var/folders/1t/xf3p_vsd7qb9k1g9t6j15hsw0000gn/T/
USER=fanxuehan
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
_CE_CONDA=''
_CE_M=''
__CFBundleIdentifier=com.apple.Terminal
http_proxy=http://127.0.0.1:10793

However, when I code curlGetHeaders(), it shows:

curlGetHeaders("https://cran.rstudio.com")
Error in curlGetHeaders("https://cran.rstudio.com") :
libcurl error code 6:
Could not resolve host: cran.rstudio.com

It shows the same error when I code curlGetHeaders() without proxy.

Ah, you are using conda, that is an important detail. If you are using conda then you should install R and all R packages with conda as well.

Alternatively, if you want to use non-conda R, then you need to deactivate conda before starting R.

When I try installing R with conda, it shows:

(base) fanxuehan@fanxuehans-MacBook-Pro ~ % conda install -c conda-forge r-base
Channels:

  • conda-forge
  • defaults
    Platform: osx-arm64

Collecting package metadata (repodata.json): \ Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x1083d9fd0>: Failed to resolve 'repo.anaconda.com' ([Errno 8] nodename nor servname provided, or not known)")': /pkgs/r/osx-arm64/repodata.json.zst

Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x1083da1e0>: Failed to resolve 'conda.anaconda.org' ([Errno 8] nodename nor servname provided, or not known)")': /conda-forge/osx-arm64/repodata.json.zst (when I run conda install, the previous error repeats over and over again)

failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://conda.anaconda.org/conda-forge/osx-arm64/repodata.json
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
'https//conda.anaconda.org/conda-forge/osx-arm64'

I cannot successfully use the command conda install, and I cannot disable conda completely (I've downloaded miniconda, but I can't delete it or disable it). What's worse, no matter what I tried, I cannot join zoom meeting now. I don't know if all these mistakes are connected internally, but I'm very, very helpless right now.

That certainly does not look like intermittent network failure, but a broken conda installation. I don't know much about conda, but according to this post you can run

conda config --set auto_activate_base false

in a terminal to turn off the automatic conda setup that happens when you start a terminal (?) or when you log in (?). So I would try to run that, then log out and log in again.

You will probably get a better answer on a conda specific forum, though.

I run the code, but it doesn't change the output when I run curlGetHeaders()or install.packages

(base) fanxuehan@fanxuehans-MacBook-Pro ~ % conda config --set auto_activate_base false