【问题标题】:Error with reading csv from URL: Error in functionalert protocol version从 URL 读取 csv 时出错:functionert 协议版本中的错误
【发布时间】:2021-10-01 07:43:33
【问题描述】:

我在从 URL 获取数据时遇到问题

weatherExists = url.exists("https://raw.githubusercontent.com/dataprofessor/data/master/weather-weka.csv")
weather <- read.csv(text = getURL("https://raw.githubusercontent.com/dataprofessor/data/master/weather-weka.csv") )

函数错误(类型、msg、asError = TRUE):错误:1407742E:SSL 例程:SSL23_GET_SERVER_HELLO:tlsv1 警报协议版本

如果您将其复制粘贴到浏览器中,则此 URL 有效,数据将显示,所以我不明白为什么该功能无法正常工作

【问题讨论】:

  • weather &lt;- read.csv('https://raw.githubusercontent.com/dataprofessor/data/master/weather-weka.csv') 为我工作。
  • getURL函数从何而来?这似乎不是基础 R。而且似乎也没有必要。

标签: r


【解决方案1】:

只需使用url 即可。

weather <- read.csv(url("https://raw.githubusercontent.com/dataprofessor/data/master/weather-weka.csv"))

head(weather)
   outlook temperature humidity windy play
1    sunny          85       85 FALSE   no
2    sunny          80       90  TRUE   no
3 overcast          83       86 FALSE  yes
4    rainy          70       96 FALSE  yes
5    rainy          68       80 FALSE  yes
6    rainy          65       70  TRUE   no

【讨论】:

    【解决方案2】:

    使用来自readr的read_csv

    readr::read_csv('https://raw.githubusercontent.com/dataprofessor/data/master/weather-weka.csv')
    # A tibble: 14 x 5
       outlook  temperature humidity windy play 
       <chr>          <dbl>    <dbl> <lgl> <chr>
     1 sunny             85       85 FALSE no   
     2 sunny             80       90 TRUE  no   
     3 overcast          83       86 FALSE yes  
     4 rainy             70       96 FALSE yes  
     5 rainy             68       80 FALSE yes  
     6 rainy             65       70 TRUE  no   
     7 overcast          64       65 TRUE  yes  
     8 sunny             72       95 FALSE no   
     9 sunny             69       70 FALSE yes  
    

    【讨论】:

      猜你喜欢
      • 2011-11-04
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      相关资源
      最近更新 更多