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.
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,
...
)
A dataframe containing a single tidy data.frame, or A list of tidy-shaped data.frames named by filename
A vector of filepaths (relative to current working directory) where each one is a tidy-shaped data file
(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_tidys
will infer filetype(s)
from the extension(s) in files
. When extension is
not "csv", "xls", or "xlsx", will use "table".
(optional) the rows and columns where
the data are located in files
.
Can be a vector or list the same length as files
, or
a single value that applies to all files
. Values
can be numeric or a string that will be automatically
converted to numeric by 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).
The sheet of the input files where data is located (if input files are .xls or .xlsx). If not specified defaults to the first
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 frame depending on the value of
the names_to_col
argument
Should the run names (provided in run_names
or inferred from files
) be added as a column to the
output?
If run_names_header
is TRUE, they will be added with
the column name "run_name"
If run_names_header
is FALSE, they will not be added.
If run_names_header
is a string, they will be added
and the column name will be the string specified
for run_names_header
.
If run_names_header
is NULL, they only will be
added if there are multiple tidy data.frames being read.
In which case, the column name will be "run_name"
If run_names are inferred from filenames, should the leading './' (if any) be retained
If run_names are inferred from filenames, should the path (if any) be retained
If run_names are inferred from filenames, should the file extension (if any) be retained
A character vector of strings which are to be interpreted
as NA
values by read.csv,
read_xls, read_xlsx,
or read.table
Deprecated, use filetype
instead
Deprecated, use run_names_header
instead
Other arguments passed to read.csv, read_xls, read_xlsx, or read.table sheet
startrow
, endrow
, startcol
, endcol
,
sheet
and filetype
can either be a single value that
applies for all files or vectors or lists the same length as files
Note that the startrow is always assumed to be a header