| read_data | R Documentation |
Reads a tabular file into a data.frame, detecting the header row with
detect_header() (the data is first read with no header so the header row is
visible as data). Delimited text (.csv/.tsv) is read with base R and always
works; spreadsheet and statistical formats use optional packages and degrade
gracefully with an actionable error if the package is absent.
read_data(
path,
header = NULL,
sheet = NULL,
na_strings = c("", "NA", "N/A", "n/a", "na", "NULL", "null", "."),
verbose = FALSE
)
path |
Path to the file. |
header |
Optional integer giving the 1-based header row to use directly,
bypassing detection. |
sheet |
Optional sheet name/index for Excel files. |
na_strings |
Character vector of tokens mapped to |
verbose |
Logical; emit the detected header row via |
Supported: .csv, .tsv/.tab (base);
.xlsx/.xls/.xlsm (Suggests: readxl or openxlsx);
.sav/.sas7bdat/.dta (Suggests: haven, header intrinsic);
.rds (base, returned as stored).
A data.frame with detected column names and per-column types
inferred via type.convert.
detect_header(), detect_roles()
tmp <- tempfile(fileext = ".csv")
writeLines(c("age,sex,score", "34,M,8.1", "51,F,7.4"), tmp)
read_data(tmp)
file.remove(tmp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.