1

I am sorry, but I cannot find the reason why my code does not work.

I want to download a csv file from here: https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide and it even tells me how to do it:

#these libraries need to be loaded
library(utils)

#read the Dataset sheet into “R”. The dataset will be called "data".
data <- read.csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", na.strings = "", fileEncoding = "UTF-8-BOM")

I always recive the error message:

Error in file(file, "rt", encoding = fileEncoding) : cannot open connection

I tried to google this, but could not find anything that would help me. The file exists (I think) and if I download it first manually and then put it into R it works fine. But I can't find the reason it does not work like it is shown.

Thank you for your help!

rbeginner
  • 41
  • 3

1 Answers1

0

Use data.table package

library(data.table)
data <- fread("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", na.strings = "")

Or use rio package along with its import() function

data <- rio::import("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", format = "csv")

Edit

head(data)

      #dateRep year_week cases_weekly deaths_weekly countriesAndTerritories geoId countryterritoryCode popData2019
#1: 18/01/2021   2021-02          557            45             Afghanistan    AF                  AFG    38041757
#2: 11/01/2021   2021-01          675            71             Afghanistan    AF                  AFG    38041757
#3: 04/01/2021   2020-53          902            60             Afghanistan    AF                  AFG    38041757
#4: 28/12/2020   2020-52         1994            88             Afghanistan    AF                  AFG    38041757
#5: 21/12/2020   2020-51          740           111             Afghanistan    AF                  AFG    38041757
#6: 14/12/2020   2020-50         1757            71             Afghanistan    AF                  AFG    38041757
   #continentExp notification_rate_per_100000_population_14-days
#1:         Asia                                            3.24
#2:         Asia                                            4.15
#3:         Asia                                            7.61
#4:         Asia                                            7.19
#5:         Asia                                            6.56
#6:         Asia                                            9.01
Daniel James
  • 1,381
  • 1
  • 10
  • 28
  • Hi, thank you for your answer; but i get this error message for both versions: Error in curl::curl_fetch_memory(file) : schannel: next InitializeSecurityContext failed: SEC_E_ILLEGAL_MESSAGE (0x80090326) - This error usually occurs when a fatal SSL/TLS alert is received (e.g. handshake failed). Do you know what might be the problem? – rbeginner Jan 25 '21 at 10:49
  • is this answer the type you like? – Daniel James Jan 25 '21 at 23:09
  • Hi, yes, this looks exactly as I want it, but with the code provided, I can not get it. Apparently it is a problem with SSL/TLS that is not reproducible on all devices/systems with no clear indication as to where exactly the problem is: https://stackoverflow.com/questions/64147821/error-running-weathercan-package-fatal-ssl-tls-alert-e-g-handshake-failed But thank you a lot for your help! – rbeginner Jan 27 '21 at 08:02