Create a source object.

datasource(file, skip = 0, skip_empty_rows = FALSE, comment = "")

Arguments

file

Either a path to a file, a connection, or literal data (either a single string or a raw vector).

Files ending in .gz, .bz2, .xz, or .zip will be automatically uncompressed. Files starting with http://, https://, ftp://, or ftps:// will be automatically downloaded. Remote gz files can also be automatically downloaded and decompressed.

Literal data is most useful for examples and tests. It must contain at least one new line to be recognised as data (instead of a path) or be a vector of greater than length 1.

Using a value of clipboard() will read from the system clipboard.

skip

Number of lines to skip before reading data.

Examples

# Literal csv datasource("a,b,c\n1,2,3")
#> [[1]] #> [1] "a,b,c\n1,2,3" #> #> $skip #> [1] 0 #> #> $skip_empty_rows #> [1] FALSE #> #> $comment #> [1] "" #> #> attr(,"class") #> [1] "source_string" "source"
datasource(charToRaw("a,b,c\n1,2,3"))
#> [[1]] #> [1] 61 2c 62 2c 63 0a 31 2c 32 2c 33 #> #> $skip #> [1] 0 #> #> $skip_empty_rows #> [1] FALSE #> #> $comment #> [1] "" #> #> attr(,"class") #> [1] "source_raw" "source"
# Strings datasource(readr_example("mtcars.csv"))
#> [[1]] #> [1] "/Users/jhester/Dropbox/projects/readr/inst/extdata/mtcars.csv" #> #> $skip #> [1] 0 #> #> $skip_empty_rows #> [1] FALSE #> #> $comment #> [1] "" #> #> attr(,"class") #> [1] "source_file" "source"
datasource(readr_example("mtcars.csv.bz2"))
#> [[1]] #> [1] "/private/var/folders/dt/r5s12t392tb5sk181j3gs4zw0000gn/T/RtmpaMtMyD/file51be5c24cb61" #> #> $skip #> [1] 0 #> #> $skip_empty_rows #> [1] FALSE #> #> $comment #> [1] "" #> #> $env #> <environment: 0x7ff27220d1e0> #> #> attr(,"class") #> [1] "source_file" "source"
datasource(readr_example("mtcars.csv.zip"))
#> [[1]] #> [1] "/private/var/folders/dt/r5s12t392tb5sk181j3gs4zw0000gn/T/RtmpaMtMyD/file51be73a47c89" #> #> $skip #> [1] 0 #> #> $skip_empty_rows #> [1] FALSE #> #> $comment #> [1] "" #> #> $env #> <environment: 0x7ff26db419c8> #> #> attr(,"class") #> [1] "source_file" "source"
# NOT RUN { datasource("https://github.com/tidyverse/readr/raw/master/inst/extdata/mtcars.csv") # }
# Connection con <- rawConnection(charToRaw("abc\n123")) datasource(con)
#> [[1]] #> [1] "/private/var/folders/dt/r5s12t392tb5sk181j3gs4zw0000gn/T/RtmpaMtMyD/file51be33ec41af" #> #> $skip #> [1] 0 #> #> $skip_empty_rows #> [1] FALSE #> #> $comment #> [1] "" #> #> $env #> <environment: 0x7ff271dbcd20> #> #> attr(,"class") #> [1] "source_file" "source"
close(con)