Skip to contents

Read data from a homogeneous list of files based on a path and a list of file names or a path and a search pattern for files. The imported data are returned as a single list object or as single data frame.

Usage

read_foreign2df(
  path = ".",
  list = NULL,
  pattern = NULL,
  recursive = FALSE,
  ignore.case = FALSE,
  bind.data = TRUE,
  .fun,
  ...
)

Arguments

path

character A path pointing to the location of the files.

list

character A vector or list of character strings pointing to files relative to path,

pattern

character A search pattern to select files within path. See list.files which is used internally. Argument ignored if list is non-null.

ignore.case, recursive

logical Passed to list.files. Arguments ignored if list is non-null.

bind.data

logical If TRUE and the values returned by .fun allow it, row bind them into a single data frame.

.fun

function An R function.

...

Named arguments passed ot the call to .fun.

Value

If bind.data = FALSE an object of class list with one member per valid file name in list or if bind.data = TRUE a data.frame resulting from row binding them with bind_rows().

Details

Function read_foreign2df() iterates over a list of file names reading them with the function passed as argument to `.fun` and collects the retured objects, usually data frames, into a named list containing them. The function passed as argument to .fun can return objects of any R class if no binding is applied, but only a data frame if a single data frame constructed by row binding the values returned by .fun and collected into the named list is to be returned by read_foreign2df().

The argument passed to .fun can be not only a function from package 'photobiologyInOut' but also any file reading function accepting a file name through a parameter named file or through a parameter named path. Examples are all R functions from package 'utils' belonging to the read.table() family, and those from packages 'foreign', 'readr', 'readODS', 'readxl', and others.

See also

Other Functions for import of data from multiple files: read_foreign2mspct()