C. Cardone
C. Cardone

Reputation: 11

How to read URL with read.csv.sql in R

I'm trying to import a csv document from a URL using the read.csv.sql {sqldf} but without success so far.

I tried the following but seems "file" is not recognized.

Any help?

read.csv.sql("https://vincentarelbundock.github.io/Rdatasets/csv/datasets/AirPassengers.csv", "select * from file")

Upvotes: 1

Views: 331

Answers (2)

akuiper
akuiper

Reputation: 214957

It seems like read.csv.sql doesn't support https:, the help page ?read.csv.sql says:

file: A file path or a URL (beginning with http:// or ftp://)

You can try the http version of the file:

library(sqldf)
read.csv.sql("http://vincentarelbundock.github.io/Rdatasets/csv/datasets/AirPassengers.csv", 
             "select * from file")

#        X     time AirPassengers
#1     "1" 1949.000           112
#2     "2" 1949.083           118
#3     "3" 1949.167           132
#4     "4" 1949.250           129
#5     "5" 1949.333           121
#6     "6" 1949.417           135
# ...

Upvotes: 1

SymbolixAU
SymbolixAU

Reputation: 26248

You can use read.csv directly on the url

read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/datasets/AirPassengers.csv")
      X     time AirPassengers
1     1 1949.000           112
2     2 1949.083           118
3     3 1949.167           132
4     4 1949.250           129
5     5 1949.333           121
6     6 1949.417           135

Upvotes: 1

Related Questions