Skip to contents

Reads the first n_rows of a tabular data file (csv/tsv/txt/dat/xlsx/xls/ ods/fods/sav/dta/sas7bdat/rds/rda/rdata). Delimiter and header presence are auto-detected for delimited text; invalid UTF-8 triggers a latin1 retry. Reading .ods/.fods needs the suggested readODS package; without it the function returns NULL for those formats.

Usage

data_read_head(path, n_rows = 5, sheet = NULL)

Arguments

path

path to a data file

n_rows

number of rows to read (Inf for all)

sheet

for .xlsx/.xls only: sheet name or 1-based index to read. NULL (default) reads the workbook's first sheet, matching readxl::read_excel()'s own default.

Value

a data.frame, or NULL on failure / unsupported format.

Examples

path <- file.path(demofile("repo"), "data", "stroop_data.csv")
data_read_head(path, n_rows = 3)
#>   participant_id congruent incongruent year
#> 1              1    21.871      21.974 2013
#> 2              2    22.820      25.116 2013
#> 3              3    14.810      18.500 2013