Reputation: 27
I'm rather new to R and I could use your assistance.
I am currently trying to import a csv file from an URL. I have found many examples. Unfortunately, none of them work for my problem.
Specifically, I wanted to import the file from this url: https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master
I tried these few lines of code:
temp <- tempfile()
download.file("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master",temp, mode = "w")
data<- read_csv2("je-b-03.03.02.05.csv")
and also this:
data <- read_csv2(url("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"))
But that didn't work either. On the other hand, when I paste the url into my browser, the file is downloaded automatically.
I would appreciate any help. Thanks
Upvotes: 1
Views: 2738
Reputation: 57
loc.url <- "https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"
data <- read.csv2(loc.url)
Upvotes: 0
Reputation: 26505
I've found vroom to be the best option for this type of task:
install.packages("vroom")
library(vroom)
data <- vroom("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master")
Upvotes: 0
Reputation:
Maybe this helps to begin with:
data <- read.csv(url("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"))
Check ?read.csv
for details.
Upvotes: 0
Reputation: 1464
df <- read.csv2(file = url("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"))
Upvotes: 2