R/import_from_file.R

library(fs)
library(readxl)

#' @title Import statistics from file
#'
#' @description This function aims at importing statistical data from an Excel file.
#' @param sourceFilePath The path where the Excel file can be found.
#' @keywords import
#' @export

import_from_file <- function(sourceFilePath){

  # Check if file exists
  # check if file is a directory
  # check if file extension is supported
  stopifnot(file.exists(sourceFilePath),
            !fs::is_dir(sourceFilePath),
            fs::path_ext(sourceFilePath) %in% c('xlsx', 'xls')
  )

  # Import from Excel
  content <- readxl::read_excel(sourceFilePath)

  # return content
  return(content)

}
thomasmotal/vs3model documentation built on June 24, 2019, 12:38 a.m.