This commit is contained in:
Andreas Gammelgaard Damsbo 2025-01-29 11:17:49 +01:00
commit 7bbc147304
No known key found for this signature in database
25 changed files with 46 additions and 36 deletions

View file

@ -80,7 +80,7 @@
#' \item \code{'all'}: a data.frame for each instrument, regardless of
#' whether it is a repeating instrument or not.
#' }
#' @include process_user_input.R utils.R
#' @include process_user_input.r utils.r
#' @export
REDCap_split <- function(records,
metadata,

View file

@ -31,7 +31,7 @@
#'
#' @return list of instruments
#' @importFrom REDCapR redcap_metadata_read redcap_read redcap_event_instruments
#' @include utils.R
#' @include utils.r
#' @export
#'
#' @examples

View file

@ -47,6 +47,12 @@ file_extension <- function(filenames) {
#' @return tibble
#' @export
#'
#' @importFrom openxlsx2 read_xlsx
#' @importFrom haven read_dta
#' @importFrom readODS read_ods
#' @importFrom readr read_csv read_rds
#'
#'
#' @examples
#' read_input("https://raw.githubusercontent.com/agdamsbo/cognitive.index.lookup/main/data/sample.csv")
read_input <- function(file, consider.na = c("NA", '""', "")) {
@ -55,15 +61,15 @@ read_input <- function(file, consider.na = c("NA", '""', "")) {
tryCatch(
{
if (ext == "csv") {
df <- readr::read_csv(file = file, na = consider.na)
df <- read_csv(file = file, na = consider.na)
} else if (ext %in% c("xls", "xlsx")) {
df <- openxlsx2::read_xlsx(file = file, na.strings = consider.na)
df <- read_xlsx(file = file, na.strings = consider.na)
} else if (ext == "dta") {
df <- haven::read_dta(file = file)
df <- read_dta(file = file)
} else if (ext == "ods") {
df <- readODS::read_ods(path = file)
df <- read_ods(path = file)
} else if (ext == "rds") {
df <- readr::read_rds(file = file)
df <- read_rds(file = file)
}else {
stop("Input file format has to be on of:
'.csv', '.xls', '.xlsx', '.dta', '.ods' or '.rds'")