1

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

rs_cit
  • 27
  • 5
  • In your first example, you should do `read.csv2(temp)`, since that's the destination of your download. – Duccio A Jan 11 '21 at 21:48

4 Answers4

2
df <- read.csv2(file = url("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"))
GWD
  • 1,387
  • 10
  • 22
0

Maybe this helps to begin with:

data <- read.csv(url("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"))

Check ?read.csvfor details.

Pax
  • 664
  • 4
  • 23
0

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")
jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
0
loc.url <- "https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"

data <- read.csv2(loc.url)
chrisAR
  • 57
  • 7