问题描述能够用浏览器访问镜像站点,但是在安装R包时遇到如下问题, # CRAN
Warning in install.packages :
unable to access index for repository https://mirrors.ustc.edu.cn/CRAN/src/contrib:
cannot open URL 'https://mirrors.ustc.edu.cn/CRAN/src/contrib/PACKAGES'
Warning in install.packages :
unable to access index for repository https://mirrors.ustc.edu.cn/CRAN/src/contrib:
cannot open URL 'https://mirrors.ustc.edu.cn/CRAN/src/contrib/PACKAGES'
Warning in install.packages :
package ‘ggtree’ is not available (for R version 3.5.1)
Warning in install.packages :
unable to access index for repository https://mirrors.ustc.edu.cn/CRAN/bin/windows/contrib/3.5:
cannot open URL 'https://mirrors.ustc.edu.cn/CRAN/bin/windows/contrib/3.5/PACKAGES'
# Bioconductor
Error: Bioconductor version cannot be validated; no internet connection?
In addition: Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘GSEABase’
2: In file(con, 'r') : InternetOpenUrl failed: '??'
3: In file(con, 'r') : InternetOpenUrl failed: 'on'
解决思路第一步,确认R能否真的能够下载数据。检索到R用 download.file 进行文件下载, download.file(url = 'https://upload-images./upload_images/2013053-6e5c996e3a0d4c93.png',
destfile = 'test.png')
发现无法直接下载内容,证明R在连接网络时出现了问题 trying URL 'https://upload-images./upload_images/2013053-6e5c996e3a0d4c93.png'
Error in download.file(url = 'https://upload-images./upload_images/2013053-6e5c996e3a0d4c93.png', :
cannot open URL 'https://upload-images./upload_images/2013053-6e5c996e3a0d4c93.png'
In addition: Warning message:
In download.file(url = 'https://upload-images./upload_images/2013053-6e5c996e3a0d4c93.png', :
InternetOpenUrl failed:
第二步,根据报错信息, 'InternetOpenUrl failed'进行检索,找到一种解决思路,也就是指定R访问网络的方法为 libcurl download.file(url = 'https://upload-images./upload_images/2013053-6e5c996e3a0d4c93.png',
destfile = 'test.png', methods='libcurl')
能够能够解决问题。 于是我修改 ~/.Rprofile ,增加如下内容 options('download.file.method'='libcurl')
# # getOption('download.file.method')
options('url.method'='libcurl')
# getOption('url.method')
# options(internet.info = 0) # 进行HTTP传输的诊断,默认是2,只会显示最后的出错信息
也就是Windows尽量设置默认的method为libcurl,因为wininet未必一直支持HTTPS。 来自于:https://github.com/r-lib/remotes/issues/45#issuecomment-262955721 注意:对于Windows系统, method='libcurl' 时可能会出现问题,也就是Windows系统不提供有效的CA certificate bundle, 也就是说默认情况下,Windows的certificates是没有被验证过的。也就是 Sys.getenv('CURL_CA_BUNDLE') 返回结果为空,建议 Sys.setenv(CURL_CA_BUNDLE=file.path(Sys.getenv('R_HOME'),'/etc/curl-ca-bundle.crt')) 打开验证。 如果没有如下图片中所指的文件,可以从https://raw./bagder/ca-bundle/master/ca-bundle.crt下载curl-ca-bundle.crt的备份。
|