
Wrapper function for reading data functions
read_fun.RdThis function receives a file extension and returns the proper reading
function from popular R packages such as: arrow, haven, readxl and
utils.
Arguments
- extension
A string specifying the file extension that must support the returned function. Supported extensions:
'parquet','feather','dta','xlsx','csv','sas','rds'and'rdata'. This parameter is case robust.- ...
Additional arguments to be passed to the reading functions encapsulated in
read_fun().
Value
A function that can read data from the specified file format. The returned function will accept the file path as its first argument.
Examples
if (FALSE) {
# Read Parquet file
reader <- read_fun("parquet")
data <- reader("file.parquet")
# Read Excel file
reader <- read_fun("xlsx")
data <- reader("file.xlsx")
# Read Parquet file
reader <- read_fun("parquet")
data <- reader("file.parquet")
# Read Excel file
reader <- read_fun("xlsx")
data <- reader("file.xlsx")
# Read CSV file with comma separator
reader <- read_fun("csv", sep = ',')
data <- reader("file.csv")
# Read TXT file with tab separator and specifying additional arguments
reader <- read_fun("txt", sep = '\t', skip = 1, header = FALSE)
data <- reader("file.txt")
}