# NOT RUN {
# Input sources -------------------------------------------------------------
# Read from a path
vroom("mtcars.tsv")
vroom("mtcars.tsv.gz")
vroom("mtcars.tsv.bz2")
# }
# NOT RUN {
# Including remote paths
vroom("https://github.com/r-lib/vroom/raw/master/inst/extdata/mtcars.csv")
# }
# NOT RUN {
# Or directly from a string (must contain a trailing newline)
vroom("x,y\n1,2\n3,4\n")
# Column selection ----------------------------------------------------------
# Pass column names or indexes directly to select them
vroom("mtcars.tsv", col_select = c(model, cyl, gear))
vroom("mtcars.tsv", col_select = c(1, 3, 11))
# Or use the selection helpers
vroom("mtcars.tsv", col_select = starts_with("d"))
# You can also rename specific columns
vroom("mtcars.tsv", col_select = list(car = model, everything()))
# Column types --------------------------------------------------------------
# By default, vroom guesses the columns types, looking at 1000 rows
# throughout the dataset.
# You can specify them explcitly with a compact specification:
vroom("x,y\n1,2\n3,4\n", col_types = "dc")
# Or with a list of column types:
vroom("x,y\n1,2\n3,4\n", col_types = list(col_double(), col_character()))
# File types ----------------------------------------------------------------
# csv
vroom("a,b\n1.0,2.0\n", delim = ",")
# tsv
vroom("a\tb\n1.0\t2.0\n")
# Other delimiters
vroom("a|b\n1.0|2.0\n", delim = "|")
# }
Run the code above in your browser using DataLab