R:直接从网站读取.DAT文件时出错

时间:2019-04-18 13:56:15

标签: r web url read.table

我正在尝试直接从website读取.DAT文件并收到以下错误:

abdomen <- read.table("https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat")

Error in file(file, "rt") : 
  cannot open the connection to 'https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat'
In addition: Warning messages:
1: In eval(formal.args[[as.character(substitute(arg))]], envir = sys.frame(sysP)) :
  closing unused connection 4 (https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat)
2: In file(file, "rt") :
  URL 'https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat': status was 'Peer certificate cannot be authenticated with given CA certificates'

我还尝试了以下代码:

abdomen <- read.table(url("https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat"))
Error in open.connection(file, "rt") : 
  cannot open the connection to 'https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat'
In addition: Warning message:
In open.connection(file, "rt") :
  URL 'https://www2.stat.duke.edu/courses/Spring03/sta113/Data/Hand/abdomen.dat': status was 'Peer certificate cannot be authenticated with given CA certificates'

请提供任何提示。

1 个答案:

答案 0 :(得分:0)

您很可能被(公司?)防火墙阻止了。确保您的代理设置正常运行。

similar question上隐藏我自己的答案:

## get the proxy settings
system("netsh winhttp show proxy")
Sys.setenv(HTTP_PROXY = <the proxy from netsh>, HTTPS_PROXY = <the proxy from netsh>)