Learn R Programming

readr (version 2.1.5)

datasource: Create a source object.

Description

Create a source object.

Usage

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

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. To be recognised as literal data, the input must be either wrapped with I(), be a string containing at least one new line, or be a vector containing at least one string with a new line.

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

skip

Number of lines to skip before reading data.

Examples

Run this code
# Literal csv
datasource("a,b,c\n1,2,3")
datasource(charToRaw("a,b,c\n1,2,3"))

# Strings
datasource(readr_example("mtcars.csv"))
datasource(readr_example("mtcars.csv.bz2"))
datasource(readr_example("mtcars.csv.zip"))
if (FALSE) {
datasource("https://github.com/tidyverse/readr/raw/main/inst/extdata/mtcars.csv")
}

# Connection
con <- rawConnection(charToRaw("abc\n123"))
datasource(con)
close(con)

Run the code above in your browser using DataLab