A function that imports tidy-shaped files into R. Largely acts as a wrapper for read.csv, read_xls, read_xls, or read_xlsx, but can handle multiple files at once and has additional options for taking subsets of rows/columns rather than the entire file and for adding filename or run names as an added column in the output.
Usage
read_tidys(
files,
filetype = NULL,
startrow = NULL,
endrow = NULL,
startcol = NULL,
endcol = NULL,
sheet = NULL,
run_names = NULL,
run_names_header = NULL,
run_names_dot = FALSE,
run_names_path = TRUE,
run_names_ext = FALSE,
na.strings = c("NA", ""),
extension,
names_to_col,
...
)Arguments
- files
A
vectorof filepaths (relative to current working directory) where each one is a tidy-shaped data file- filetype
(optional) the type(s) of the files. Options include:
"csv", "xls", or "xlsx".
"tbl" or "table" to use read.table to read the file, "csv2" to use read.csv2, "delim" to use read.delim, or "delim2" to use read.delim2.
If none provided,
read_tidyswill infer filetype(s) from the extension(s) infiles. When extension is not "csv", "xls", or "xlsx", will use "table".- startrow, endrow, startcol, endcol
(optional) the rows and columns where the data are located in
files.Can be a
vectororlistthe same length asfiles, or a single value that applies to allfiles. Values can benumericor astringthat will be automatically converted tonumericby from_excel.If not provided, data is presumed to begin on the first row and column of the file(s) and end on the last row and column of the file(s).
- sheet
The sheet of the input files where data is located (if input files are .xls or .xlsx). If not specified defaults to the first
- run_names
Names to give the tidy files read in. By default uses the file names if not specified. These names may be added to the resulting
data.framedepending on the value of thenames_to_colargument- run_names_header
Should the run names (provided in
run_namesor inferred fromfiles) be added as a column to the output?If
run_names_headerisTRUE, they will be added with the column namerun_nameIf
run_names_headerisFALSE, they will not be added.If
run_names_headeris astring, they will be added and the column name will be thestringspecified forrun_names_header.If
run_names_headerisNULL, they only will be added if there are multiple tidydata.frames being read. In which case, the column name will berun_name- run_names_dot
If
run_namesare inferred from filenames, should the leading './' (if any) be retained- run_names_path
If
run_namesare inferred from filenames, should the path (if any) be retained- run_names_ext
If
run_namesare inferred from filenames, should the file extension (if any) be retained- na.strings
A
charactervectorofstrings which are to be interpreted asNAvalues by read.csv, read_xls, read_xlsx, or read.table- extension
Deprecated, use
filetypeinstead- names_to_col
Deprecated, use
run_names_headerinstead- ...
Other arguments passed to read.csv, read_xls, read_xlsx, or read.table sheet