Get Started With Vroom

Reading files

To read a CSV, or other type of delimited file with vroom pass the file to vroom(). The delimiter will be automatically guessed if it is a common delimiter; e.g. (“,” “” ” “|” “:” “;”). If the guessing fails or you are using a less common delimiter specify it with the delim parameter. (e.g. delim = ",").

We have included an example CSV file in the vroom package for use in examples and tests. Access it with vroom_example("mtcars.csv")

# See where the example file is stored on your machine file <- vroom_example("mtcars.csv") file #> [1] "/private/tmp/RtmpR72M8H/Rinstd3457201fe3c/vroom/extdata/mtcars.csv" # Read the file, by default vroom will guess the delimiter automatically. vroom(file) #> Rows: 32 Columns: 12 #> ── Column specification ──────────────────────────────────────────────────────── #> Delimiter: "," #> chr (1): model #> dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb #> #> ℹ Use `spec()` to retrieve the full column specification for this data. #> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. #> # A tibble: 32 × 12 #> model mpg cyl disp hp drat wt qsec vs am gear carb #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 Mazda RX4 21 6 160 110 3.9 2.62 16.5 0 1 4 4 #> 2 Mazda RX4 W… 21 6 160 110 3.9 2.88 17.0 0 1 4 4 #> 3 Datsun 710 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 #> # ℹ 29 more rows # You can also specify it explicitly, which is (slightly) faster, and safer if # you know how the file is delimited. vroom(file, delim = ",") #> Rows: 32 Columns: 12 #> ── Column specification ──────────────────────────────────────────────────────── #> Delimiter: "," #> chr (1): model #> dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb #> #> ℹ Use `spec()` to retrieve the full column specification for this data. #> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. #> # A tibble: 32 × 12 #> model mpg cyl disp hp drat wt qsec vs am gear carb #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 Mazda RX4 21 6 160 110 3.9 2.62 16.5 0 1 4 4 #> 2 Mazda RX4 W… 21 6 160 110 3.9 2.88 17.0 0 1 4 4 #> 3 Datsun 710 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 #> # ℹ 29 more rows

Từ khóa » Vroom Col_select