@@ -387,7 +387,7 @@ canlang_data
387
387
```
388
388
389
389
### Reading tabular data directly from a URL
390
- We can also use ` read_csv ` , ` read_tsv ` or ` read_delim ` (and related functions)
390
+ We can also use ` read_csv ` , ` read_tsv ` , or ` read_delim ` (and related functions)
391
391
to read in data directly from a ** U** niform ** R** esource ** L** ocator (URL) that
392
392
contains tabular data. \index{URL!reading from} Here, we provide the URL of a remote file to
393
393
` read_* ` , instead of a path to a local file on our
@@ -402,6 +402,24 @@ canlang_data <- read_csv(url)
402
402
canlang_data
403
403
```
404
404
405
+ ### Downloading data from a URL
406
+ Occasionally the data available at a URL is not formatted nicely enough to use
407
+ ` read_csv ` , ` read_tsv ` , ` read_delim ` , or other related functions to read the data
408
+ directly into R. In situations where it is necessary to download a file
409
+ to our local computer prior to working with it in R, we can use the ` download.file `
410
+ function. The first argument is the URL, and the second is a path where we would
411
+ like to store the downloaded file.
412
+
413
+ ``` r
414
+ download.file(url , " data/can_lang.csv" )
415
+ canlang_data <- read_csv(" data/can_lang.csv" )
416
+ canlang_data
417
+ ```
418
+
419
+ ``` {r echo=FALSE, warning = FALSE}
420
+ canlang_data
421
+ ```
422
+
405
423
### Previewing a data file before reading it into R
406
424
407
425
In many of the examples above, we gave you previews of the data file before we read
0 commit comments