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

1
  • In your first example, you should do read.csv2(temp), since that's the destination of your download. Commented Jan 11, 2021 at 21:48

4 Answers 4

2
df <- read.csv2(file = url("https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"))
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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")

Comments

0
loc.url <- "https://www.bfs.admin.ch/bfsstatic/dam/assets/15324797/master"

data <- read.csv2(loc.url)

4 Comments

I am not saying your answer is wrong, but please provide a bit more context to why it is correct.
@chrisAR Please provide some context in your answer
Look on that line:"file can also be a complete URL. (For the supported URL schemes, see the ‘URLs’ section of the help for url."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.