# NOT RUN {
# Show path to example file
input_file <- vroom_example("mtcars.csv")
# Read from a path
# Input sources -------------------------------------------------------------
# Read from a path
vroom(input_file)
# You can also use literal paths directly
# vroom("mtcars.csv")
# }
# 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(input_file, col_select = c(model, cyl, gear))
vroom(input_file, col_select = c(1, 3, 11))
# Or use the selection helpers
vroom(input_file, col_select = starts_with("d"))
# You can also rename specific columns
vroom(input_file, 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