R/read_data.R

Defines functions read_data load_file.tsv_path load_file.xlsx_path load_file.xls_path load_file.csv_path load_file set_path_class

set_path_class <- function(file_path){
  #' @keywords internal
  ext <- tolower(tools::file_ext(file_path))

  class(file_path) <- c(glue::glue("{ext}_path"), "path", class(file_path))

  file_path
}

load_file <- function(file_path){
  UseMethod("load_file")
}

load_file.csv_path <- function(file_path, ...){
  #' @importFrom readr read_csv
  read_csv(file_path, ...)
}

load_file.xls_path <- function(file_path, ...){
  #' @importFrom openxlsx read.xlsx
  read.xlsx(file_path,  ...)
}

load_file.xlsx_path <- function(file_path, ...){
  #' @importFrom openxlsx read.xlsx
  read.xlsx(file_path,  ...)
}

load_file.tsv_path <- function(file_path, ...){
  #' @importFrom readr read_tsv
  read_tsv(file_path,  ...)
}

read_data <- function(file_path, ...){
  file_path <- set_path_class(file_path)

  load_file(file_path, ...)
}

Try the deident package in your browser

Any scripts or data that you put into this service are public.

deident documentation built on April 3, 2025, 6:14 p.m.