read.to.list {readmoRe} | R Documentation |
Read various input file formats into a list of data frames. Wrapper function for 'read2list' to automate reading further and avoid errors due to missing folders or files.
Description
read.to.list
is meant to act as a universal reading function as it attempts to read
a number of different file formats into a list of data frames.
Usage
read.to.list(
dat,
type,
folder,
nsheets = 1,
sheet = NULL,
keep.tibble = FALSE,
skip = 0,
sep = NULL,
lines = FALSE,
dec = NULL,
...,
verbose = TRUE,
x.verbose = FALSE
)
Arguments
dat |
|
type |
|
folder |
|
nsheets |
|
sheet |
|
keep.tibble |
|
skip |
|
sep |
|
lines |
|
dec |
|
... |
Additional arguments passed to functions. |
verbose |
|
x.verbose |
|
Details
Excel files (file extension .xls or .xlsx) will be read by readxl::read_excel
. A test is attempted
to determine whether the input file is genuinely derived from Excel or only named like an nExcel file. If the latter,
it will be attempted to read it as text file.
Text files are read as tables or by line if lines
is TRUE
.
For text files, field delimiters and decimal separators are determined automatically if not provided.
Files with the extensions .txt", ".tsv", ".csv", ".gtf" and ".gff" are treated and read as text files.
VCF files are also treated as text files but can noly be read in full (incl. header) if read by line. Otherwise,
if skip
is 0
, the line with the column names will be determined automatically and the file read
as delimited text file.
XML files are read by xml2::read_xml
.
".RData" files are loaded and assigned a name.
".rds" and ".rda" files are read by readRDS
.
".xdr" files are read by R.utils::loadObject
.
Value
A list of tibbles/data frames.
See Also
Examples
# The function readxl::read_excel is used internally to read Excel files.
# The example used their example data.
readxl_datasets <- readxl::readxl_example("datasets.xlsx")
# A randomly generated data frame was saved to a tab-separated text file
# and two different R object files.
tsv_datasets <- dir(system.file("extdata", package = "readmoRe"), full.names = TRUE)
# All example data are read into a list. From the Excel file, the first
# sheet is read.
dat <- read.to.list(c(readxl_datasets, tsv_datasets))
# All example data are read into a list. From the Excel file, the first
# 3 sheets are read.
dat <- read.to.list(c(readxl_datasets, tsv_datasets), nsheets=3)
# All example data are read into a list. From the Excel file, sheets 1 and
# 4 are read.
dat <- read.to.list(c(readxl_datasets, tsv_datasets), sheet=c(1, 4))
# From two Excel files, different sheets are read: 1 and 4 from the first
# file and 2 and 3 from the second.
# (For simplicity, the same example file is used.)
dat <- read.to.list(c(readxl_datasets, readxl_datasets), sheet=list(c(1, 4), c(2, 3)))