read_csv: Read csv file checking for correct row number

View source: R/05_moreUtils.R

read_csvR Documentation

Read csv file checking for correct row number

Description

NOTE: This function is currently not exported since some cases cannot be tested. Sometimes read_csv stops reading in a csv file after several lines without any message. This function is a wrapper around read_csv that counts the number of rows in the original file and compares it with the resulting data.frame. If the numbers of rows differ, it throws a warning.

Usage

read_csv(file, col_names = TRUE, skip = 0, n_max = Inf, ...)

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.

col_names

Either TRUE, FALSE or a character vector of column names.

If TRUE, the first row of the input will be used as the column names, and will not be included in the data frame. If FALSE, column names will be generated automatically: X1, X2, X3 etc.

If col_names is a character vector, the values will be used as the names of the columns, and the first row of the input will be read into the first row of the output data frame.

Missing (NA) column names will generate a warning, and be filled in with dummy names ...1, ...2 etc. Duplicate column names will generate a warning and be made unique, see name_repair to control how this is done.

skip

Number of lines to skip before reading data. If comment is supplied any commented lines are ignored after skipping.

n_max

Maximum number of lines to read.

...

arguments passed to read_csv

Examples

write.csv(x = iris, file = "iris.csv")
read_csv(file = "iris.csv")
read_csv(file = "iris.csv", skip = 3, col_names = FALSE, n_max = 10)


INWT/INWTUtils documentation built on May 22, 2024, 4:45 p.m.