The key to reading R
documentation is school algebra, f(x) = y.
In either the R
console or the RStudio
console type
?read_csv
to get the f unction signature
read_csv(file, col_names = TRUE, col_types = NULL,
locale = default_locale(), na = c("", "NA"), quoted_na = TRUE,
quote = """, comment = "", trim_ws = TRUE, skip = 0,
n_max = Inf, guess_max = min(1000, n_max),
progress = show_progress(), skip_empty_rows = TRUE)
Each of file
, col_names
, col_types
are arguments to f with or without
(NULL). The possible values are described under "Arguments"
The first argument is crucial. Identifying the wrong type of object to a function (e.g., a character type when a numeric is expected). Then look at the description
col_types One of NULL, a cols() specification, or a string. See vignette("readr") for more details.
If NULL, all column types will be imputed from the first 1000 rows on the input. This is convenient (and fast), but not robust. If the imputation fails, you'll need to supply the correct types yourself.
If a column specification created by cols(), it must contain one column specification for each column. If you only want to read a subset of the columns, use cols_only().
Alternatively, you can use a compact string representation where each character represents one column: c = character, i = integer, n = number, d = double, l = logical, f = factor, D = date, T = date time, t = time, ? = guess, or _/- to skip the column.
The answer to the question is in the last paragraph: n
is an integer, nn
is two integers`.
Notice a subtle gotcha, 235
is a double, not an integer
. That makes post-processing with the follow-on function preferable when a variable number of digits are to be expected.
Do not neglect, either, the Values, which describes what f returns, the examples, which should be run as a test of understanding f and any references for underlying details of algorithms involved.