From 532aaf5785ab188f2018c9e041cb6ee3e4c69ec4 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Thu, 17 Oct 2024 23:20:46 +0800 Subject: [PATCH 01/37] Refactor code in the R/ folder --- R/dvloader.R | 150 +++++++++++++++++++++++++++++------------- R/utils.R | 180 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 218 insertions(+), 112 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index a36a7b9..2d22547 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -1,61 +1,119 @@ -#' gets the NFS base path from an env var -#' It assumes there is an env var -#' called RXD_DATA which holds the path suffix. -#' @return the NFS base path +#' Get Base Directory Path +#' +#' This function retrieves the base directory path from a specified environment variable. +#' It checks if the environment variable is set and if the directory exists. +#' +#' @param env_var [character(1)] The name of the environment variable containing the base directory path. +#' +#' @return [character(1)] The normalized path to the base directory. +#' +#' @examples +#' # Create a temporary directory +#' temp_dir <- tempdir() +#' +#' # Set the BASE_DIR environment variable +#' Sys.setenv(BASE_DIR = temp_dir) +#' +#' # Get the base directory path +#' get_base_dir("BASE_DIR") +#' #' @export -get_nfs_path <- function() { - base_path <- Sys.getenv("RXD_DATA") - # check that RXD_DATA is set - if (base_path == "") { - stop("Usage: get_nfs_path: RXD_DATA must be set") +get_base_dir <- function(env_var) { + # Ensure env_var is a single character string + checkmate::assert_character(env_var, len = 1) + + # Get the value of the environment variable + base_dir <- Sys.getenv(env_var) + + # Stop if the environment variable is not set + if (base_dir == "") { + stop("Environment variable ", env_var, " is not set") } - return(base_path) + + # Ensure the directory exists + checkmate::assert_directory_exists(base_dir) + + # Return the normalized path + return(normalizePath(base_dir)) } -#' gets the NFS base path from an env var -#' alias for get_nfs_path to maintain backwards compatibility -#' @export -get_cre_path <- get_nfs_path - -#' Loads data into memory based on study directory and one or more file_names. -#' @param sub_dir A relative directory/folder that will be appended to a base path defined by `Sys.getenv("RXD_DATA")`. -#' If the argument is left as NULL, the function will load data from the working directory `getwd()`. -#' @param file_names Study file or file_names name(s) - can be a vector of strings. -#' This is the only required argument. -#' @param use_wd for "use working directory" - a flag used when importing local files -#' not on NFS - default value is FALSE -#' @param prefer_sas if set to TRUE, imports sas7bdat files first before looking for -#' RDS files (the opposite of default behavior) -#' @return a list of dataframes + +#' Get CRE Path +#' +#' This function retrieves the path to the CRE (Clinical Research Environment) directory. +#' It uses the "RXD_DATA" environment variable as the base directory. +#' +#' @return [character(1)] The path to the CRE directory. +#' #' @export +get_cre_path <- function() { + get_base_dir(env_var = "RXD_DATA") +} + + +#' Load Data Files +#' +#' This function loads data files from a specified directory or the current working directory. +#' It supports loading both RDS and SAS7BDAT files. +#' +#' @param sub_dir [character(1)] Optional character string specifying a subdirectory. Default is NULL. +#' @param file_names [character(1+)] Character vector of file names to load (without extension). +#' @param use_wd [logical(1)] Logical indicating whether to use the current working directory. Default is FALSE. +#' @param prefer_sas [logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE. +#' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". +#' +#' @return A named list of data frames, where each name corresponds to a loaded file. +#' #' @examples #' \dontrun{ -#' test_data_path <- "../inst/extdata/" -#' data_list <- load_data( -#' sub_dir = test_data_path, -#' file_names = "dummyads2", -#' use_wd = TRUE -#' ) +#' # Load RDS files from the directory specified by RXD_DATA environment variable +#' data_list <- load_data(file_names = c("adsl", "adae")) +#' +#' # Load SAS files from a subdirectory in the current working directory +#' data_list <- load_data(sub_dir = "adam", file_names = c("adsl", "adae"), use_wd = TRUE, prefer_sas = TRUE) #' } -load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE) { - if (is.null(file_names)) { - stop("Usage: load_data: file_names: Must supply at least one file name") - } - - study_path <- "" # will be built using args +#' +#' # Set the BASE_DIR environment variable +#' Sys.setenv(BASE_DIR = find.package("haven")) +#' +#' # Get the base directory path +#' base_dir <- get_base_dir("BASE_DIR") +#' list.files(base_dir) +#' list.files(file.path(base_dir, "examples")) +#' +#' # Load data files +#' data_list <- load_data(sub_dir = "examples", file_names = "iris.sas7bdat", env_var = "BASE_DIR") +#' str(data_list) +#' +#' @export +load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE, env_var = "RXD_DATA") { + # Input validation + checkmate::assert_character(sub_dir, len = 1, null.ok = TRUE) + checkmate::assert_character(file_names, min.len = 1) + checkmate::assert_logical(use_wd, len = 1) + checkmate::assert_logical(prefer_sas, len = 1) + checkmate::assert_character(env_var, len = 1) - if (is.null(sub_dir)) { - study_path <- getwd() + # Determine the base directory + if (use_wd) { + base_dir <- getwd() } else { - if (use_wd) { - study_path <- file.path(getwd(), sub_dir) - } else { - study_path <- file.path(get_cre_path(), sub_dir) - } + base_dir <- get_base_dir(env_var = env_var) } + + # Construct the full directory path + dir_path <- if (is.null(sub_dir)) base_dir else file.path(base_dir, sub_dir) + + # Determine the file extension based on preference + file_ext <- if (prefer_sas) "sas7bdat" else "rds" + + # Get the full file paths + file_paths <- get_file_paths(dir_path = dir_path, file_names = file_names, prefer_sas = prefer_sas) + + # Load the data files + data_list <- load_data_files(file_paths) - # create the output - data_list <- create_data_list(study_path, file_names, prefer_sas) # nolint + names(data_list) <- file_names return(data_list) } diff --git a/R/utils.R b/R/utils.R index a3791e1..fed9f31 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,81 +1,129 @@ -#' For each file name provided, reads in the first matching file and its meta data/attributes. -#' Preference is given to RDS because its faster -#' @param file_path the folder where the files are -#' @param file_names CDISC names for the files -#' @param prefer_sas if TRUE, imports .sas7bdat files first instead of .RDS files -#' @return returns a list of dataframes with metadata as an attribute on each dataframe -create_data_list <- function(file_path, file_names, prefer_sas) { - data_list <- lapply(file_names, function(x) { - extensions <- c("", ".rds", ".sas7bdat") - if (prefer_sas) { - extensions <- c("", ".sas7bdat", ".rds") - } - - file_name_to_load <- NULL - - candidates <- list.files(file_path) - uppercase_candidates <- Map(toupper, candidates) - - for (ext in extensions) { - # Case insensitive file name match - uppercase_file_name <- toupper(paste0(x, ext)) - - match_count <- sum(uppercase_candidates == uppercase_file_name) - if (match_count > 1) { - stop(paste("create_data_list(): More than one case-insensitive file name match for", file_path, x)) +#' Get File Paths +#' +#' This function constructs file paths for given file names, handling both RDS and SAS7BDAT files. +#' It can prioritize SAS files over RDS files based on the `prefer_sas` parameter. +#' +#' @param dir_path [character(1)] The directory path where the files are located. +#' @param file_names [character(1+)] A vector of file names to process. +#' @param prefer_sas [logical(1)] Whether to prefer SAS files over RDS files. Default is FALSE. +#' +#' @return [character] A vector of normalized file paths. +#' +#' @examples +#' temp_dir <- tempdir() +#' +#' file_names <- c("adsl", "adae") +#' +#' file.create(file.path(temp_dir, paste0(file_names, ".rds"))) +#' file.create(file.path(temp_dir, paste0(file_names, ".sas7bdat"))) +#' +#' list.files(temp_dir) +#' +#' get_file_paths(dir_path = temp_dir, file_names = file_names) +#' get_file_paths(dir_path = temp_dir, file_names = file_names, prefer_sas = TRUE) +#' +#' unlink(temp_dir, recursive = TRUE) +#' +#' @export +get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { + # Input validation + checkmate::assert_character(dir_path, len = 1) + checkmate::assert_character(file_names, min.len = 1) + checkmate::assert_logical(prefer_sas, len = 1) + + file_paths <- lapply(file_names, function(file_name) { + file_path <- file.path(dir_path, file_name) + file_ext <- tools::file_ext(file_name) + + if (file_ext == "") { + # If no extension is provided, check for both RDS and SAS files + rds_file_name <- paste0(file_name, ".rds") + sas_file_name <- paste0(file_name, ".sas7bdat") + rds_file_path <- file.path(dir_path, rds_file_name) + sas_file_path <- file.path(dir_path, sas_file_name) + + if (isTRUE(prefer_sas)) { + # Prefer SAS file if it exists, otherwise use RDS + if (file.exists(sas_file_path)) { + return(sas_file_path) + } else if (file.exists(rds_file_path)) { + return(rds_file_path) + } else { + stop(dir_path, " does not contain: ", rds_file_name, " or ", sas_file_name) + } + } else if (isFALSE(prefer_sas)) { + # Prefer RDS file if it exists, otherwise use SAS + if (file.exists(rds_file_path)) { + return(rds_file_path) + } else if (file.exists(sas_file_path)) { + return(sas_file_path) + } else { + stop(dir_path, " does not contain: ", rds_file_name, " or ", sas_file_name) + } } - - index <- match(uppercase_file_name, uppercase_candidates) - if (!is.na(index)) { - file_name_to_load <- candidates[[index]] - break + } else { + # If an extension is provided, use the exact file name + if (file.exists(file_path)) { + return(file_path) + } else { + stop(dir_path, " does not contain: ", file_name) } } - - if (is.null(file_name_to_load)) { - stop(paste("create_data_list(): No RDS or SAS files found for", file_path, x)) - } - - output <- read_file(file_path, file_name_to_load) - - return(output) }) - names(data_list) <- file_names - - return(data_list) + # Normalize all file paths + return(normalizePath(unlist(file_paths))) } -#' Reads RDS/SAS file and metadatas from first 6 items from file.info() its file path -#' @param file_path a path to a file -#' @param file_name name of a file -#' @return a data object with an extra attribute of metadata -read_file <- function(file_path, file_name) { - ext <- tools::file_ext(file_name) - if (!(toupper(ext) %in% c("RDS", "SAS7BDAT"))) { - stop("Usage error: read_file: file_name: file must either be RDS or SAS7BDAT.") - } +#' Load Data Files +#' +#' This function reads data from multiple file paths and returns a list of data frames. +#' It supports reading RDS and SAS7BDAT files. +#' +#' @param file_paths [character(1+)] A vector of file paths to read. +#' +#' @return [list] A named list of data frames, where each name is the basename of the corresponding file path. +#' +#' @examples +#' path <- system.file("examples", "iris.sas7bdat", package = "haven") +#' data_list <- load_data_files(file_paths = path) +#' str(data_list) +#' +#' @export +load_data_files <- function(file_paths) { + # Validate input parameters + checkmate::assert_character(file_paths, min.len = 1) + checkmate::assert_file_exists(file_paths) + + # Read each file and store in a list + data_list <- lapply(file_paths, function(file_path) { + # Get file extension + extension <- tools::file_ext(file_path) + + # Read file based on its extension + if (tolower(extension) == "rds") { + data <- readRDS(file_path) + } else if (tolower(extension) == "sas7bdat") { + data <- haven::read_sas(file_path) + } else { + stop("Unsupported file extension: ", extension) + } - is_rds <- toupper(ext) == "RDS" + # Get file metadata + meta <- file.info(file_path, extra_cols = FALSE) + meta[["path"]] <- file_path + meta[["file_name"]] <- basename(file_path) - file <- file.path(file_path, file_name) - file_name <- tools::file_path_sans_ext(file_name) + # Add metadata as an attribute to the data + attr(data, "meta") <- as.list(meta) - # grab file info - meta <- file.info(file)[1L:6L] - meta[["path"]] <- row.names(meta) - meta[["file_name"]] <- file_name - meta <- data.frame(meta, stringsAsFactors = FALSE) - row.names(meta) <- NULL + return(data) + }) - if (is_rds) { - out <- readRDS(file) - } else { - out <- haven::read_sas(file) - } - attr(out, "meta") <- meta + # Set names of the list elements to the basenames of the file paths + names(data_list) <- basename(file_paths) - return(out) + return(data_list) } From ff5d20262174b036f00791a481ef3f1c08b491e4 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Fri, 18 Oct 2024 10:41:47 +0800 Subject: [PATCH 02/37] Update examples --- R/dvloader.R | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index 2d22547..4a3e7b0 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -65,26 +65,18 @@ get_cre_path <- function() { #' @return A named list of data frames, where each name corresponds to a loaded file. #' #' @examples -#' \dontrun{ -#' # Load RDS files from the directory specified by RXD_DATA environment variable -#' data_list <- load_data(file_names = c("adsl", "adae")) -#' -#' # Load SAS files from a subdirectory in the current working directory -#' data_list <- load_data(sub_dir = "adam", file_names = c("adsl", "adae"), use_wd = TRUE, prefer_sas = TRUE) -#' } +#' # Get the current value of the RXD_DATA environment variable +#' base_dir <- Sys.getenv("RXD_DATA") #' -#' # Set the BASE_DIR environment variable -#' Sys.setenv(BASE_DIR = find.package("haven")) +#' # Set the RXD_DATA environment variable to the path of the haven package +#' Sys.setenv(RXD_DATA = find.package("haven")) #' -#' # Get the base directory path -#' base_dir <- get_base_dir("BASE_DIR") -#' list.files(base_dir) -#' list.files(file.path(base_dir, "examples")) -#' -#' # Load data files -#' data_list <- load_data(sub_dir = "examples", file_names = "iris.sas7bdat", env_var = "BASE_DIR") +#' data_list <- load_data(sub_dir = "examples", file_names = c("iris.sas7bdat")) #' str(data_list) #' +#' # Reset the RXD_DATA environment variable to its original value +#' Sys.setenv(RXD_DATA = base_dir) +#' #' @export load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE, env_var = "RXD_DATA") { # Input validation From 432e835beb4e876e549410c600b10a955c2c45b5 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Fri, 18 Oct 2024 10:42:38 +0800 Subject: [PATCH 03/37] Print the directory path and file names --- R/dvloader.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/dvloader.R b/R/dvloader.R index 4a3e7b0..3e3d557 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -102,6 +102,10 @@ load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = F # Get the full file paths file_paths <- get_file_paths(dir_path = dir_path, file_names = file_names, prefer_sas = prefer_sas) + # Print the directory path and file names + cat("Loading data from", dir_path, "\n") + cat("Loading data file(s):", basename(file_paths), "\n") + # Load the data files data_list <- load_data_files(file_paths) From 9ec6f69872d8f46c6e109df8437fcdd74669b8d0 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Mon, 21 Oct 2024 16:12:22 +0800 Subject: [PATCH 04/37] Add an arugment to print file paths if requested --- R/dvloader.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index 3e3d557..b6cb43d 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -61,6 +61,7 @@ get_cre_path <- function() { #' @param use_wd [logical(1)] Logical indicating whether to use the current working directory. Default is FALSE. #' @param prefer_sas [logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE. #' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". +#' @param print_file_paths [logical(1)] Logical indicating whether to print the directory path and file names. Default is FALSE. #' #' @return A named list of data frames, where each name corresponds to a loaded file. #' @@ -78,7 +79,7 @@ get_cre_path <- function() { #' Sys.setenv(RXD_DATA = base_dir) #' #' @export -load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE, env_var = "RXD_DATA") { +load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE, env_var = "RXD_DATA", print_file_paths = FALSE) { # Input validation checkmate::assert_character(sub_dir, len = 1, null.ok = TRUE) checkmate::assert_character(file_names, min.len = 1) @@ -102,9 +103,11 @@ load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = F # Get the full file paths file_paths <- get_file_paths(dir_path = dir_path, file_names = file_names, prefer_sas = prefer_sas) - # Print the directory path and file names - cat("Loading data from", dir_path, "\n") - cat("Loading data file(s):", basename(file_paths), "\n") + # Print the directory path and file names if requested + if (isTRUE(print_file_paths)) { + cat("Loading data from", dir_path, "\n") + cat("Loading data file(s):", basename(file_paths), "\n") + } # Load the data files data_list <- load_data_files(file_paths) From bda40b4bac503ac130c98d8c5701b94dc88ffe69 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Mon, 21 Oct 2024 16:14:58 +0800 Subject: [PATCH 05/37] Do not export get_base_dir() --- R/dvloader.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index b6cb43d..ae8d0fb 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -16,8 +16,7 @@ #' #' # Get the base directory path #' get_base_dir("BASE_DIR") -#' -#' @export +#' get_base_dir <- function(env_var) { # Ensure env_var is a single character string checkmate::assert_character(env_var, len = 1) From b155b1aec2fac95fdd8422cc1d036810d75efb72 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Mon, 21 Oct 2024 16:42:13 +0800 Subject: [PATCH 06/37] Add get_nfs_path() function back --- R/dvloader.R | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/R/dvloader.R b/R/dvloader.R index ae8d0fb..ee8bb82 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -36,12 +36,25 @@ get_base_dir <- function(env_var) { return(normalizePath(base_dir)) } +#' Get NFS Path +#' +#' This function retrieves the path to the NFS (Network File System) directory. +#' +#' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". +#' +#' @return [character(1)] The path to the NFS directory. +#' +#' @export +get_nfs_path <- function(env_var = "RXD_DATA") { + get_base_dir(env_var = env_var) +} + #' Get CRE Path #' #' This function retrieves the path to the CRE (Clinical Research Environment) directory. #' It uses the "RXD_DATA" environment variable as the base directory. -#' +#' #' @return [character(1)] The path to the CRE directory. #' #' @export From f7601bf9c6454f570f753ced13641451eac0955f Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Mon, 21 Oct 2024 16:49:08 +0800 Subject: [PATCH 07/37] Keep the metadata format unchanged --- R/utils.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index fed9f31..93ac178 100644 --- a/R/utils.R +++ b/R/utils.R @@ -117,7 +117,8 @@ load_data_files <- function(file_paths) { meta[["file_name"]] <- basename(file_path) # Add metadata as an attribute to the data - attr(data, "meta") <- as.list(meta) + rownames(data) <- NULL + attr(data, "meta") <- meta return(data) }) From 65704612be3e7b30dce670fee17324e90cee46d1 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Tue, 22 Oct 2024 19:30:50 +0800 Subject: [PATCH 08/37] Update README --- README.md | 77 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1199129..ab3eadc 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,75 @@ -# Data Loading - -The {dv.loader} package provides a simple interface for loading data from a network file storage folder or -locally. It is designed to be used with `.RDS` and `.sas7bdat` file formats. -The package provides a simple function, `load_data()`, which loads R and SAS data files into memory. -Loading data from SQL databases is not yet supported. The function returns a list named by the file names passed, -and containing data frames, along with metadata for that table. By default, the function will look for files in a -sub-directory `sub_dir` of the base path defined by a environment variable "RXD_DATA". You can check if the base path -is set by running `Sys.getenv("RXD_DATA")`. A single file or multiple files can be loaded at once. -To make the loading process faster for large datasets, it is suggested that '.sas7bdat' files are converted to -'.RDS' files. The function will prefer '.RDS' files over '.sas7bdat' files by default. +# dv.loader + +The `dv.loader` package is designed to simplify the data loading process for creating modular Shiny applications within the DaVinci framework. + +Key features of `dv.loader` include: + +1. Capability to import multiple files from a data directory. + +2. Compatibility with both `.rds` and `.sas7bdat` file types. + +3. Smooth integration with other packages in the DaVinci ecosystem. + ## Installation +You can install the `dv.loader` package from GitHub using the `remotes` package: + ```r +# Install the remotes package if not already installed if (!require("remotes")) install.packages("remotes") + +# Install the dv.loader package from GitHub remotes::install_github("Boehringer-Ingelheim/dv.loader") ``` -## Basic usage +## Examples + +The main function is `dv.loader::load_data()`, which loads data files from sub-directories of a network file system (NFS) or the working directory. + +### Example 1: Sub-directory of Network File System (NFS) + +To load data files from a NFS, you need to set the NFS path as an environment variable. By default, the environment variable name is `RXD_DATA`. + +You can run the following command to check the NFS path if it is already set. ```r -# getting data from a network file storage folder -dv.loader::load_data(sub_dir = "subdir1/subdir2", file_names = c("adsl", "adae")) +# Check the NFS path +dv.loader::get_nfs_path() ``` +If the NFS path is not set, you can set it by running the following command. + ```r -# getting data locally (e.g., if you have file `./data/adsl.RDS`) -dv.loader::load_data(sub_dir = "data", file_names = c("adsl"), use_wd = TRUE) +# Set the NFS path as an environment variable +Sys.setenv(RXD_DATA = "path/to/network-file-system") ``` + +The environment variable setup is not needed if you have already set the NFS path as an environment variable in your `.Renviron` or `.Rprofile` file. + +If the NFS path has been properly set, you can load data files from the NFS and its sub-directories. + +```r +# Load data files from the specified sub-directory of a network file system (NFS) +dv.loader::load_data( + sub_dir = "sub-directory/of/network-file-system", + file_names = c("adsl.sas7bdat", "adae.sas7bdat") +) +``` + +For the `file_names` argument, it is recommended to use the full file names including the file extension. + +### Example 2: Sub-directory of the Working Directory + +To load data files from a local directory, there is no need to set an environment variable. You use `use_wd = TRUE` to indicate that the data files are loaded from a sub-directory of the working directory. + +```r +# Load data files from the specified sub-directory of the working directory +dv.loader::load_data( + sub_dir = "sub-directory/of/working-directory", + file_names = c("adsl.sas7bdat", "adae.sas7bdat"), + use_wd = TRUE +) +``` + +Additional examples can be found in the package vignettes. From 488d6792b9cbdb5904e99c6dfc0ef8b5aad5cccf Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Tue, 22 Oct 2024 19:47:44 +0800 Subject: [PATCH 09/37] Update package vignettes --- vignettes/.gitignore | 2 + vignettes/integration-guide.Rmd | 65 ++++++++++++++++++++++++++ vignettes/loading-data-into-memory.Rmd | 45 ------------------ 3 files changed, 67 insertions(+), 45 deletions(-) create mode 100644 vignettes/.gitignore create mode 100644 vignettes/integration-guide.Rmd delete mode 100644 vignettes/loading-data-into-memory.Rmd diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/integration-guide.Rmd b/vignettes/integration-guide.Rmd new file mode 100644 index 0000000..802f252 --- /dev/null +++ b/vignettes/integration-guide.Rmd @@ -0,0 +1,65 @@ +--- +title: "Integration Guide" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Integration Guide} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +This vignette showcases the integration of the {dv.loader} package with other packages from the DaVinci framework. It guides you through the process of combining {dv.loader} with {dv.manager} and {dv.listings} to create a modular Shiny application. + +```{r, eval=FALSE} +# Install the {remotes} package if you haven't already +if (!require("remotes")) install.packages("remotes") + +# Define the packages to install +pkgs <- c("dv.loader", "dv.manager", "dv.listings") + +# Install the packages from GitHub +remotes::install_github(repo = paste0("Boehringer-Ingelheim/", pkgs)) +``` + +## Step 1: Load data files + +```{r, eval=FALSE} +# Set the NFS path as an environment variable +Sys.setenv(RXD_DATA = "path/to/network-file-system") + +# Load data files from the specified sub-directory of a network file system (NFS) +data_list <- dv.loader::load_data( + sub_dir = "sub-directory/of/network-file-system", + file_names = c("adsl.sas7bdat", "adae.sas7bdat") +) +``` + +## Step 2: Create a module list + +```{r, eval=FALSE} +# Include a module containing two data listings +module_list <- list( + "Data Listings" = dv.listings::mod_listings( + module_id = "data_listings", + dataset_names = c("adsl.sas7bdat", "adae.sas7bdat") + ) +) +``` + +## Step 3: Run the DaVinci application + +```{r, eval=FALSE} +# Run the DaVinci application with data and module lists defined earlier +dv.manager::run_app( + data = list("Datasets" = data_list), + module_list = module_list, + filter_data = "adsl.sas7bdat", + title = "DaVinci Application" +) +``` diff --git a/vignettes/loading-data-into-memory.Rmd b/vignettes/loading-data-into-memory.Rmd deleted file mode 100644 index 577da15..0000000 --- a/vignettes/loading-data-into-memory.Rmd +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: "Loading Data into Memory" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Loading Data into Memory} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -```{r setup} -library(dv.loader) -``` - -Note: `use_wd = TRUE` can be used to source from local folder. Just set your working directory before using with `setwd()`, or use an explicit path in `sub_dir`. - -## Usage: `load_data()` - -```{r} -test_data_path <- "../tests/testthat/inst/extdata" -data_list <- load_data( - sub_dir = test_data_path, - file_names = "dummyads2", - use_wd = TRUE -) - - -class(data_list) - -class(data_list[["dummyads2"]]) - -head(data_list[["dummyads2"]]) -``` - -Get the dataframe's metadata through its attributes: - -```{r} -attr(data_list[["dummyads2"]], "meta") -``` From 1f256bcb4a5839b28fca458f643150030044fdf3 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Tue, 22 Oct 2024 22:53:56 +0800 Subject: [PATCH 10/37] Add sample data for docs and tests --- inst/extdata/data.R | 41 ++++++++++++++++++ inst/extdata/pharmaverseadam/adae_sample.rds | Bin 0 -> 5592 bytes .../pharmaverseadam/adae_sample.sas7bdat | Bin 0 -> 69632 bytes inst/extdata/pharmaverseadam/adsl_sample.rds | Bin 0 -> 2201 bytes .../pharmaverseadam/adsl_sample.sas7bdat | Bin 0 -> 28672 bytes 5 files changed, 41 insertions(+) create mode 100644 inst/extdata/data.R create mode 100644 inst/extdata/pharmaverseadam/adae_sample.rds create mode 100644 inst/extdata/pharmaverseadam/adae_sample.sas7bdat create mode 100644 inst/extdata/pharmaverseadam/adsl_sample.rds create mode 100644 inst/extdata/pharmaverseadam/adsl_sample.sas7bdat diff --git a/inst/extdata/data.R b/inst/extdata/data.R new file mode 100644 index 0000000..29c1d03 --- /dev/null +++ b/inst/extdata/data.R @@ -0,0 +1,41 @@ +# Create directory for pharmaverseadam data if it doesn't exist +data_dir <- file.path("inst", "extdata", "pharmaverseadam") +if (!dir.exists(data_dir)) { + dir.create(data_dir, recursive = TRUE) +} + +# Sample 10 subjects from adsl data +set.seed(123) # For reproducibility +adsl_sample <- pharmaverseadam::adsl |> + dplyr::sample_n(size = 10) + +# Filter adae data for the 10 subjects in adsl_sample +adae_sample <- pharmaverseadam::adae |> + dplyr::filter(USUBJID %in% adsl_sample$USUBJID) + +# Save adsl_sample to rds file +saveRDS( + object = adsl_sample, + file = file.path(data_dir, "adsl_sample.rds") +) + +# Save adae_sample to rds file +saveRDS( + object = adae_sample, + file = file.path(data_dir, "adae_sample.rds") +) + +# Write adsl_sample to sas7bdat file +haven::write_sas( + data = adsl_sample, + path = file.path(data_dir, "adsl_sample.sas7bdat") +) + +# Write adae_sample to sas7bdat file +haven::write_sas( + data = adae_sample, + path = file.path(data_dir, "adae_sample.sas7bdat") +) + +# Add a message to confirm data creation +message("Sample data files have been created in ", data_dir) diff --git a/inst/extdata/pharmaverseadam/adae_sample.rds b/inst/extdata/pharmaverseadam/adae_sample.rds new file mode 100644 index 0000000000000000000000000000000000000000..f806ce5f2455dcda329ba63dd5458b71127e9414 GIT binary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J-!*8l***DSRF literal 0 HcmV?d00001 diff --git a/inst/extdata/pharmaverseadam/adae_sample.sas7bdat b/inst/extdata/pharmaverseadam/adae_sample.sas7bdat new file mode 100644 index 0000000000000000000000000000000000000000..28722160375269cf77e12bd2ce35fdac40c42677 GIT binary patch literal 69632 zcmeG_ZHybobtCB{ourc^$BN@Na=fusS4nj;dAu*#O0;|A-jOknWR^Th=NgdcJL-<< ziM;T5`UupTMU++v{KE*;51>J#qWX~p{!ySt>Y{E!6hULOZmKp0>HtQQ7AcUX3Lq3} z8?;K?_h#Pga+lmYE;q_uk|DsIeKYUP$D4U?=FQhK=KTKZd%t<+Pxs&d_ka1Bezxmt z(H9%>hx`L)+Y? zZj%2)Zf^xC4k!*N4k!*N4k!*N4k!*N4k!*N4*b|T@Za#mNK2lW{|9~^ua4mFlRfiz z$I$k8+t6U&ai`zgo?j;%<)=8X`8lu!w*NEs5KaQX@4I`2%RT8;IX`1!S=xMICNY~zutav+NM#tC$h0h<JKAk)p%QEca#xpcjxI=uUFCFpVxo$N2=VfQ3Ke@$|tTU6CBehvb-% zn6Y>{!JPp(oyg`P;b}O0bHae4Lw?NZ$u!WJCpaE(D+MrB7qccYfjGFLJl5nX?g1|M zuqIP+5uW2PFAp#RT!@9Se5zpbdY%GaO_?)!^Axj;xM>!WnH1m|)-+Zxy3B|dI4E4k z;@O!@!J1`>X-om)oKDO_ek0Kw=U*fWr+x%Kr@4y^!SW!Z&?Oj3o?!X7HHi!YKIaSI zPFg28zbqq@z!%7`f%TIHC~2k>>3qRR0}AAM%7PP4d1I272lI{|mN}KmW}*TgJb)?| z0St@>U%;I}H(y_!zoez+OO<;0Y`IiRRL>R570r0=xmxLbxmYh(D{Q7x{@7|s%dbB7 z(b8PK1sVBQf}qM=Nz1IBd#+St`Q>V5rCJ+Il+KnbrFj>!Ra&mr>fl)@)y`>Wt2M2@ zSkjF7^QGEKNi)ww9$311p|n!h(xvmIC5{JawE1cA>O2gZ66HC}U$J%xlB<=^Q_L(^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c;|8{3*uR46z6i3TmnNkL@r_dKN?FK>GVt-K5Kz%S%*bu8JOgU-wO^_R5%FZ(v(t|OOD ze|b99)?c!={*vN$=H=XS>9+rsT;AjUvV&kLug$=LHSK@f&fxc^OoGCkn(21mR4{C* z@p_{YHW5d5QCL45j>x@b+g_3A}c0QNmZ{_=k{Os8OxXw5p z%r*~(E#^0Y^?`$YO9@ zc))%+^<7S6hWh@WY!W{o?v|~*oa^XKJZC%!kPJ>5Q@VZZJf&uAZSw#MlN9J#Te;}iMjcb~DWC!4o`izI8^Gmhcvr#PTEpg5p7pg5p7pg6D@Iq?7O CR6)D| literal 0 HcmV?d00001 diff --git a/inst/extdata/pharmaverseadam/adsl_sample.rds b/inst/extdata/pharmaverseadam/adsl_sample.rds new file mode 100644 index 0000000000000000000000000000000000000000..35fe401dadf7e9f59eb1dd032dcb23efcaf2e934 GIT binary patch literal 2201 zcmV;K2xj*miwFP!000001MOPNbKAxlheS}6oQKuAPR5>TjihcK)1eB86eT6o4q+0M zm{24GfU$gNRhV2#$dCXFg0_`It?8wm&h(N)ubF8tJ@%MOr@VIBu`d1tdg`^kw9}K_ zT>uO00t-rt8abW>Gve;|*v0RA>=W9(#Bp4POEk&X5R!3`sZiLYSW;e+ifbfG5)q5mD&-}yC{bD)P-|VJSg^0vO`27NZ(LuCH!Q4E zeTj&*R-jm@;cCG*f9`3_;%gnt{MiHu+T`v>pzF>yohNMO31fM}N}e!}C+y-0gLuLc zo-lzYu=6uOGtdfs+Y#IYXb6fR1N)^_QCfvw&7)qqrKj)-%SfYuGzt>ML9s3|bw$`) ziRKg&oOQ@da5hpbdktHrfi+NO)!fKc$kXwql z8&Q?eEwU6uqFPMBc-0?Hn(2b%+WRtsS=P%OddiI>ztpCF+2;IG56UK%2jvGryH240 z0T(<>AQ^d|H3etyD6*>(JK77!ZteW7ZP&(!`~MEh-X z|A6dZM&C>k+aK4fVBB@g5n4>W)irX@^Ay(0a@U<0gRi3+%$BjJM&4lswWG-wQDsBT zR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iX$mdTlYnOFuK_baXP_Ju_wuGc$v~ z)~T+bJ*P5A(nz6WvKMD9aUd5xa zspuG1xN)p-Exc*0W+ZmZ@q2KwO~nK*Y>_f^IBO*z!fIuubD5+yZ&-6FesMXf8IN#G ztXej@n`&m%S9lR?{NX1*pla4QOc^*%ZQ{v<%sI9R;H#>cZ|g4+c_CY2zcgR1M2}-d z>$PU4Va-4>f*;QU-ghQNKFny0?l?^ztgtc44B+7xz$tT@N6+X!v)gKRv{-pO3%43* zs~c{)RB?@L^*H}77I{jUU(KeYV-(C}L*b;uF+_aqc}ryG*{2?)%p?wqj5H2WX4t(6 zJ~je35q~{__v(dtxIq@gttL?ry3*FKZvI6}X2AZE?lV{i#%AE&KO^dq0J!&AE~GKv zWXd$TNqznUs%Efn5y1cim#3Ps1ZAoTauX%V3$|S{!&#SfpNYfXY-$33V$Hx9#hSsp z>Qpx#?afe()ocQm%ajRQ3^?k2-e-F4zk131HG?}!0n}Bysb=Rcz9;r(kN^DvSso&gL&13?kt)#o{&Cu^9WhRE1nHa~P$ih@KhEFkkCu-8Yr^$nQ&UXML z#x;X?n<+|CqtM?Dpx3>mm(0%$>|>_HG%;H<(|WU#nelm`f9|e3MP|PHy?f=Fxn5+X zej8 Date: Wed, 23 Oct 2024 10:23:27 +0800 Subject: [PATCH 11/37] Update Rd files --- man/create_data_list.Rd | 23 ------------------ man/get_base_dir.Rd | 30 ++++++++++++++++++++++++ man/get_cre_path.Rd | 10 ++++---- man/get_file_paths.Rd | 38 ++++++++++++++++++++++++++++++ man/get_nfs_path.Rd | 15 ++++++------ man/load_data.Rd | 52 +++++++++++++++++++++++++---------------- man/load_data_files.Rd | 24 +++++++++++++++++++ man/read_file.Rd | 19 --------------- 8 files changed, 137 insertions(+), 74 deletions(-) delete mode 100644 man/create_data_list.Rd create mode 100644 man/get_base_dir.Rd create mode 100644 man/get_file_paths.Rd create mode 100644 man/load_data_files.Rd delete mode 100644 man/read_file.Rd diff --git a/man/create_data_list.Rd b/man/create_data_list.Rd deleted file mode 100644 index 2368307..0000000 --- a/man/create_data_list.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{create_data_list} -\alias{create_data_list} -\title{For each file name provided, reads in the first matching file and its meta data/attributes. -Preference is given to RDS because its faster} -\usage{ -create_data_list(file_path, file_names, prefer_sas) -} -\arguments{ -\item{file_path}{the folder where the files are} - -\item{file_names}{CDISC names for the files} - -\item{prefer_sas}{if TRUE, imports .sas7bdat files first instead of .RDS files} -} -\value{ -returns a list of dataframes with metadata as an attribute on each dataframe -} -\description{ -For each file name provided, reads in the first matching file and its meta data/attributes. -Preference is given to RDS because its faster -} diff --git a/man/get_base_dir.Rd b/man/get_base_dir.Rd new file mode 100644 index 0000000..891d825 --- /dev/null +++ b/man/get_base_dir.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dvloader.R +\name{get_base_dir} +\alias{get_base_dir} +\title{Get Base Directory Path} +\usage{ +get_base_dir(env_var) +} +\arguments{ +\item{env_var}{[character(1)] The name of the environment variable containing the base directory path.} +} +\value{ +[character(1)] The normalized path to the base directory. +} +\description{ +This function retrieves the base directory path from a specified environment variable. +It checks if the environment variable is set and if the directory exists. +} +\examples{ +# Create a temporary directory +temp_dir <- tempdir() + +# Set the BASE_DIR environment variable +Sys.setenv(BASE_DIR = temp_dir) + +# Get the base directory path +dv.loader:::get_base_dir("BASE_DIR") + +} +\keyword{internal} diff --git a/man/get_cre_path.Rd b/man/get_cre_path.Rd index 86b2b78..03686b2 100644 --- a/man/get_cre_path.Rd +++ b/man/get_cre_path.Rd @@ -2,12 +2,14 @@ % Please edit documentation in R/dvloader.R \name{get_cre_path} \alias{get_cre_path} -\title{gets the NFS base path from an env var -alias for get_nfs_path to maintain backwards compatibility} +\title{Get CRE Path} \usage{ get_cre_path() } +\value{ +[character(1)] The path to the CRE directory. +} \description{ -gets the NFS base path from an env var -alias for get_nfs_path to maintain backwards compatibility +This function retrieves the path to the CRE (Clinical Research Environment) directory. +It uses the "RXD_DATA" environment variable as the base directory. } diff --git a/man/get_file_paths.Rd b/man/get_file_paths.Rd new file mode 100644 index 0000000..dc19143 --- /dev/null +++ b/man/get_file_paths.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{get_file_paths} +\alias{get_file_paths} +\title{Get File Paths} +\usage{ +get_file_paths(dir_path, file_names, prefer_sas = FALSE) +} +\arguments{ +\item{dir_path}{[character(1)] The directory path where the files are located.} + +\item{file_names}{[character(1+)] A vector of file names to process.} + +\item{prefer_sas}{[logical(1)] Whether to prefer SAS files over RDS files. Default is FALSE.} +} +\value{ +[character] A vector of normalized file paths. +} +\description{ +This function constructs file paths for given file names, handling both RDS and SAS7BDAT files. +It can prioritize SAS files over RDS files based on the `prefer_sas` parameter. +} +\examples{ +temp_dir <- tempdir() + +file_names <- c("adsl", "adae") + +file.create(file.path(temp_dir, paste0(file_names, ".rds"))) +file.create(file.path(temp_dir, paste0(file_names, ".sas7bdat"))) + +list.files(temp_dir) + +get_file_paths(dir_path = temp_dir, file_names = file_names) +get_file_paths(dir_path = temp_dir, file_names = file_names, prefer_sas = TRUE) + +unlink(temp_dir, recursive = TRUE) + +} diff --git a/man/get_nfs_path.Rd b/man/get_nfs_path.Rd index 5cbad09..3c4ba73 100644 --- a/man/get_nfs_path.Rd +++ b/man/get_nfs_path.Rd @@ -2,17 +2,16 @@ % Please edit documentation in R/dvloader.R \name{get_nfs_path} \alias{get_nfs_path} -\title{gets the NFS base path from an env var -It assumes there is an env var -called RXD_DATA which holds the path suffix.} +\title{Get NFS Path} \usage{ -get_nfs_path() +get_nfs_path(env_var = "RXD_DATA") +} +\arguments{ +\item{env_var}{[character(1)] The environment variable name for the base directory. Default is "RXD_DATA".} } \value{ -the NFS base path +[character(1)] The path to the NFS directory. } \description{ -gets the NFS base path from an env var -It assumes there is an env var -called RXD_DATA which holds the path suffix. +This function retrieves the path to the NFS (Network File System) directory. } diff --git a/man/load_data.Rd b/man/load_data.Rd index 5367158..50f7187 100644 --- a/man/load_data.Rd +++ b/man/load_data.Rd @@ -2,36 +2,48 @@ % Please edit documentation in R/dvloader.R \name{load_data} \alias{load_data} -\title{Loads data into memory based on study directory and one or more file_names.} +\title{Load Data Files} \usage{ -load_data(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE) +load_data( + sub_dir = NULL, + file_names, + use_wd = FALSE, + prefer_sas = FALSE, + env_var = "RXD_DATA", + print_file_paths = FALSE +) } \arguments{ -\item{sub_dir}{A relative directory/folder that will be appended to a base path defined by `Sys.getenv("RXD_DATA")`. -If the argument is left as NULL, the function will load data from the working directory `getwd()`.} +\item{sub_dir}{[character(1)] Optional character string specifying a subdirectory. Default is NULL.} + +\item{file_names}{[character(1+)] Character vector of file names to load (without extension).} + +\item{use_wd}{[logical(1)] Logical indicating whether to use the current working directory. Default is FALSE.} -\item{file_names}{Study file or file_names name(s) - can be a vector of strings. -This is the only required argument.} +\item{prefer_sas}{[logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE.} -\item{use_wd}{for "use working directory" - a flag used when importing local files -not on NFS - default value is FALSE} +\item{env_var}{[character(1)] The environment variable name for the base directory. Default is "RXD_DATA".} -\item{prefer_sas}{if set to TRUE, imports sas7bdat files first before looking for -RDS files (the opposite of default behavior)} +\item{print_file_paths}{[logical(1)] Logical indicating whether to print the directory path and file names. Default is FALSE.} } \value{ -a list of dataframes +A named list of data frames, where each name corresponds to a loaded file. } \description{ -Loads data into memory based on study directory and one or more file_names. +This function loads data files from a specified directory or the current working directory. +It supports loading both RDS and SAS7BDAT files. } \examples{ -\dontrun{ -test_data_path <- "../inst/extdata/" -data_list <- load_data( - sub_dir = test_data_path, - file_names = "dummyads2", - use_wd = TRUE -) -} +# Get the current value of the RXD_DATA environment variable +base_dir <- Sys.getenv("RXD_DATA") + +# Set the RXD_DATA environment variable to the path of the haven package +Sys.setenv(RXD_DATA = find.package("haven")) + +data_list <- load_data(sub_dir = "examples", file_names = c("iris.sas7bdat")) +str(data_list) + +# Reset the RXD_DATA environment variable to its original value +Sys.setenv(RXD_DATA = base_dir) + } diff --git a/man/load_data_files.Rd b/man/load_data_files.Rd new file mode 100644 index 0000000..ccaac13 --- /dev/null +++ b/man/load_data_files.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{load_data_files} +\alias{load_data_files} +\title{Load Data Files} +\usage{ +load_data_files(file_paths) +} +\arguments{ +\item{file_paths}{[character(1+)] A vector of file paths to read.} +} +\value{ +[list] A named list of data frames, where each name is the basename of the corresponding file path. +} +\description{ +This function reads data from multiple file paths and returns a list of data frames. +It supports reading RDS and SAS7BDAT files. +} +\examples{ +path <- system.file("examples", "iris.sas7bdat", package = "haven") +data_list <- load_data_files(file_paths = path) +str(data_list) + +} diff --git a/man/read_file.Rd b/man/read_file.Rd deleted file mode 100644 index e46767b..0000000 --- a/man/read_file.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{read_file} -\alias{read_file} -\title{Reads RDS/SAS file and metadatas from first 6 items from file.info() its file path} -\usage{ -read_file(file_path, file_name) -} -\arguments{ -\item{file_path}{a path to a file} - -\item{file_name}{name of a file} -} -\value{ -a data object with an extra attribute of metadata -} -\description{ -Reads RDS/SAS file and metadatas from first 6 items from file.info() its file path -} From 30619aba5051fdbd973ea81d63a89919a2378a8e Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 13:50:20 +0800 Subject: [PATCH 12/37] Update tests --- tests/testthat.R | 5 ++++- tests/testthat/tests.R | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/testthat.R b/tests/testthat.R index 8d34285..784ab0f 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,6 @@ pkg_name <- "dv.loader" + +library(testthat) library(pkg_name, character.only = TRUE) -testthat::test_check(pkg_name) + +test_check(pkg_name) diff --git a/tests/testthat/tests.R b/tests/testthat/tests.R index d5e5747..b5e0527 100644 --- a/tests/testthat/tests.R +++ b/tests/testthat/tests.R @@ -205,3 +205,18 @@ test_that( expect_equal(grepl(".RDS$", actual), TRUE) } ) + +test_that( + "prefer_sas is not used if file extension is included in file_names" %>% + vdoc[["add_spec"]](specs$prefer_sas), + { + data_list <- load_data( + sub_dir = local_test_path, + file_names = c("dummyads1.RDS", "dummyads2.sas7bdat"), + use_wd = TRUE, + prefer_sas = FALSE + ) + expect_equal(tools::file_ext(attr(data_list[[1]], "meta")$path), "RDS") + expect_equal(tools::file_ext(attr(data_list[[2]], "meta")$path), "sas7bdat") + } +) From 8298ec2c1beb7927434516b948d129418def066f Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 13:59:31 +0800 Subject: [PATCH 13/37] Update test setup file --- tests/testthat/setup.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 1dab7a6..47bcc78 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,9 +1,7 @@ # validation (S) vdoc <- local({ - # ########## # package_name is used # INSIDE # the sourced file below - # ########## - package_name <- read.dcf("../../DESCRIPTION")[, "Package"] + package_name <- "dv.loader" # read.dcf("../../DESCRIPTION")[, "Package"] utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE) source(utils_file_path, local = TRUE)[["value"]] }) From 9cb51ac4d4da716bdc2426e3556de34ef6597401 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 14:00:35 +0800 Subject: [PATCH 14/37] Update integration guide --- vignettes/integration-guide.Rmd | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vignettes/integration-guide.Rmd b/vignettes/integration-guide.Rmd index 802f252..f142d6c 100644 --- a/vignettes/integration-guide.Rmd +++ b/vignettes/integration-guide.Rmd @@ -31,12 +31,13 @@ remotes::install_github(repo = paste0("Boehringer-Ingelheim/", pkgs)) ```{r, eval=FALSE} # Set the NFS path as an environment variable -Sys.setenv(RXD_DATA = "path/to/network-file-system") +Sys.setenv(RXD_DATA = find.package("dv.loader")) # Load data files from the specified sub-directory of a network file system (NFS) data_list <- dv.loader::load_data( - sub_dir = "sub-directory/of/network-file-system", - file_names = c("adsl.sas7bdat", "adae.sas7bdat") + sub_dir = "extdata/pharmaverseadam", + file_names = c("adsl_sample", "adae_sample"), + print_file_paths = TRUE ) ``` @@ -47,7 +48,7 @@ data_list <- dv.loader::load_data( module_list <- list( "Data Listings" = dv.listings::mod_listings( module_id = "data_listings", - dataset_names = c("adsl.sas7bdat", "adae.sas7bdat") + dataset_names = c("adsl_sample", "adae_sample") ) ) ``` @@ -57,9 +58,9 @@ module_list <- list( ```{r, eval=FALSE} # Run the DaVinci application with data and module lists defined earlier dv.manager::run_app( - data = list("Datasets" = data_list), + data = list("Demo Data" = data_list), module_list = module_list, - filter_data = "adsl.sas7bdat", + filter_data = "adsl_sample", title = "DaVinci Application" ) ``` From 01de80362398a9f717523100b8b16152fcba1473 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 14:01:23 +0800 Subject: [PATCH 15/37] Make get_base_dir internal function --- R/dvloader.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/dvloader.R b/R/dvloader.R index ee8bb82..c07a534 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -15,8 +15,9 @@ #' Sys.setenv(BASE_DIR = temp_dir) #' #' # Get the base directory path -#' get_base_dir("BASE_DIR") +#' dv.loader:::get_base_dir("BASE_DIR") #' +#' @keywords internal get_base_dir <- function(env_var) { # Ensure env_var is a single character string checkmate::assert_character(env_var, len = 1) From b111f9a5c38456acdcca990fe1ce2deff19bf14b Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 14:01:53 +0800 Subject: [PATCH 16/37] Export get_file_paths and load_data_files --- NAMESPACE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 79ce8a0..be207da 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand export(get_cre_path) +export(get_file_paths) export(get_nfs_path) export(load_data) +export(load_data_files) From a4801246b54c1fd1a58ee69ab2366c5de2f91ce7 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 14:02:11 +0800 Subject: [PATCH 17/37] Update DESCRIPTION file --- DESCRIPTION | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a12e282..05bf0ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: dv.loader Type: Package Title: Data loading module -Version: 2.0.0 +Version: 2.1.0 Authors@R: c( person( "Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")), person( given = "Ming", family = "Yang", role = c("aut", "cre"), email = "ming.yang.ext@boehringer-ingelheim.com"), @@ -13,10 +13,13 @@ License: Apache License (>= 2) Encoding: UTF-8 LazyData: true Depends: R (>= 3.5.0) -Imports: haven +Imports: + checkmate, + haven Suggests: - testthat, + testthat (>= 3.0.0), knitr, rmarkdown RoxygenNote: 7.3.0 VignetteBuilder: knitr +Config/testthat/edition: 3 From 8722c94e24ca4f589a1ef706b3aca953a2251a52 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 14:20:45 +0800 Subject: [PATCH 18/37] Update changelog --- NEWS.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS.md b/NEWS.md index a5c5124..e3df5dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# dv.loader 2.1.0 + +- Refactored code to improve readability and maintainability. + +- Fixed issue of partial matching when the `file_names` argument contains no file extensions. + +- Added arguments `env_var` and `print_file_paths` in `load_data()` function to provide more flexibility and control. + # dv.loader 2.0.0 - GitHub release with QC report From 8bcefd3ffa78c10c7a969d652d10f0ab7d947478 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 14:43:10 +0800 Subject: [PATCH 19/37] Update roxygen examples --- R/utils.R | 2 ++ man/get_file_paths.Rd | 2 ++ 2 files changed, 4 insertions(+) diff --git a/R/utils.R b/R/utils.R index 93ac178..c7a0089 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,6 +10,7 @@ #' @return [character] A vector of normalized file paths. #' #' @examples +#' \dontrun{ #' temp_dir <- tempdir() #' #' file_names <- c("adsl", "adae") @@ -23,6 +24,7 @@ #' get_file_paths(dir_path = temp_dir, file_names = file_names, prefer_sas = TRUE) #' #' unlink(temp_dir, recursive = TRUE) +#' } #' #' @export get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { diff --git a/man/get_file_paths.Rd b/man/get_file_paths.Rd index dc19143..57751eb 100644 --- a/man/get_file_paths.Rd +++ b/man/get_file_paths.Rd @@ -21,6 +21,7 @@ This function constructs file paths for given file names, handling both RDS and It can prioritize SAS files over RDS files based on the `prefer_sas` parameter. } \examples{ +\dontrun{ temp_dir <- tempdir() file_names <- c("adsl", "adae") @@ -34,5 +35,6 @@ get_file_paths(dir_path = temp_dir, file_names = file_names) get_file_paths(dir_path = temp_dir, file_names = file_names, prefer_sas = TRUE) unlink(temp_dir, recursive = TRUE) +} } From 5b719dd80cb812141672ba4b5ee379f496f9b12f Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 15:08:16 +0800 Subject: [PATCH 20/37] Fix lintr issues --- R/dvloader.R | 12 ++++++++++-- tests/testthat/setup.R | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index c07a534..b983c00 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -74,7 +74,8 @@ get_cre_path <- function() { #' @param use_wd [logical(1)] Logical indicating whether to use the current working directory. Default is FALSE. #' @param prefer_sas [logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE. #' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". -#' @param print_file_paths [logical(1)] Logical indicating whether to print the directory path and file names. Default is FALSE. +#' @param print_file_paths [logical(1)] Logical indicating whether to print the directory path and file names. +#' Default is FALSE. #' #' @return A named list of data frames, where each name corresponds to a loaded file. #' @@ -92,7 +93,14 @@ get_cre_path <- function() { #' Sys.setenv(RXD_DATA = base_dir) #' #' @export -load_data <- function(sub_dir = NULL, file_names, use_wd = FALSE, prefer_sas = FALSE, env_var = "RXD_DATA", print_file_paths = FALSE) { +load_data <- function( + sub_dir = NULL, + file_names, + use_wd = FALSE, + prefer_sas = FALSE, + env_var = "RXD_DATA", + print_file_paths = FALSE + ) { # Input validation checkmate::assert_character(sub_dir, len = 1, null.ok = TRUE) checkmate::assert_character(file_names, min.len = 1) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 47bcc78..7e92070 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,7 +1,7 @@ # validation (S) vdoc <- local({ # package_name is used # INSIDE # the sourced file below - package_name <- "dv.loader" # read.dcf("../../DESCRIPTION")[, "Package"] + package_name <- "dv.loader" utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE) source(utils_file_path, local = TRUE)[["value"]] }) From 62545e96e276152044cdd4ae60091aff978fb9c1 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 15:09:24 +0800 Subject: [PATCH 21/37] Fix styler issues --- R/dvloader.R | 41 ++++++++++++++++----------------- R/utils.R | 16 ++++++------- tests/testthat/setup.R | 2 +- vignettes/integration-guide.Rmd | 6 ++--- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index b983c00..139ea8c 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -10,13 +10,13 @@ #' @examples #' # Create a temporary directory #' temp_dir <- tempdir() -#' +#' #' # Set the BASE_DIR environment variable #' Sys.setenv(BASE_DIR = temp_dir) -#' +#' #' # Get the base directory path #' dv.loader:::get_base_dir("BASE_DIR") -#' +#' #' @keywords internal get_base_dir <- function(env_var) { # Ensure env_var is a single character string @@ -42,12 +42,12 @@ get_base_dir <- function(env_var) { #' This function retrieves the path to the NFS (Network File System) directory. #' #' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". -#' +#' #' @return [character(1)] The path to the NFS directory. #' #' @export get_nfs_path <- function(env_var = "RXD_DATA") { - get_base_dir(env_var = env_var) + get_base_dir(env_var = env_var) } @@ -55,12 +55,12 @@ get_nfs_path <- function(env_var = "RXD_DATA") { #' #' This function retrieves the path to the CRE (Clinical Research Environment) directory. #' It uses the "RXD_DATA" environment variable as the base directory. -#' +#' #' @return [character(1)] The path to the CRE directory. #' #' @export get_cre_path <- function() { - get_base_dir(env_var = "RXD_DATA") + get_base_dir(env_var = "RXD_DATA") } @@ -74,7 +74,7 @@ get_cre_path <- function() { #' @param use_wd [logical(1)] Logical indicating whether to use the current working directory. Default is FALSE. #' @param prefer_sas [logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE. #' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". -#' @param print_file_paths [logical(1)] Logical indicating whether to print the directory path and file names. +#' @param print_file_paths [logical(1)] Logical indicating whether to print the directory path and file names. #' Default is FALSE. #' #' @return A named list of data frames, where each name corresponds to a loaded file. @@ -82,25 +82,24 @@ get_cre_path <- function() { #' @examples #' # Get the current value of the RXD_DATA environment variable #' base_dir <- Sys.getenv("RXD_DATA") -#' +#' #' # Set the RXD_DATA environment variable to the path of the haven package #' Sys.setenv(RXD_DATA = find.package("haven")) -#' +#' #' data_list <- load_data(sub_dir = "examples", file_names = c("iris.sas7bdat")) #' str(data_list) -#' +#' #' # Reset the RXD_DATA environment variable to its original value #' Sys.setenv(RXD_DATA = base_dir) -#' +#' #' @export load_data <- function( - sub_dir = NULL, - file_names, - use_wd = FALSE, - prefer_sas = FALSE, - env_var = "RXD_DATA", - print_file_paths = FALSE - ) { + sub_dir = NULL, + file_names, + use_wd = FALSE, + prefer_sas = FALSE, + env_var = "RXD_DATA", + print_file_paths = FALSE) { # Input validation checkmate::assert_character(sub_dir, len = 1, null.ok = TRUE) checkmate::assert_character(file_names, min.len = 1) @@ -114,7 +113,7 @@ load_data <- function( } else { base_dir <- get_base_dir(env_var = env_var) } - + # Construct the full directory path dir_path <- if (is.null(sub_dir)) base_dir else file.path(base_dir, sub_dir) @@ -125,7 +124,7 @@ load_data <- function( file_paths <- get_file_paths(dir_path = dir_path, file_names = file_names, prefer_sas = prefer_sas) # Print the directory path and file names if requested - if (isTRUE(print_file_paths)) { + if (isTRUE(print_file_paths)) { cat("Loading data from", dir_path, "\n") cat("Loading data file(s):", basename(file_paths), "\n") } diff --git a/R/utils.R b/R/utils.R index c7a0089..b84d8c1 100644 --- a/R/utils.R +++ b/R/utils.R @@ -12,17 +12,17 @@ #' @examples #' \dontrun{ #' temp_dir <- tempdir() -#' +#' #' file_names <- c("adsl", "adae") -#' +#' #' file.create(file.path(temp_dir, paste0(file_names, ".rds"))) #' file.create(file.path(temp_dir, paste0(file_names, ".sas7bdat"))) -#' +#' #' list.files(temp_dir) -#' +#' #' get_file_paths(dir_path = temp_dir, file_names = file_names) #' get_file_paths(dir_path = temp_dir, file_names = file_names, prefer_sas = TRUE) -#' +#' #' unlink(temp_dir, recursive = TRUE) #' } #' @@ -36,14 +36,14 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { file_paths <- lapply(file_names, function(file_name) { file_path <- file.path(dir_path, file_name) file_ext <- tools::file_ext(file_name) - + if (file_ext == "") { # If no extension is provided, check for both RDS and SAS files rds_file_name <- paste0(file_name, ".rds") sas_file_name <- paste0(file_name, ".sas7bdat") rds_file_path <- file.path(dir_path, rds_file_name) sas_file_path <- file.path(dir_path, sas_file_name) - + if (isTRUE(prefer_sas)) { # Prefer SAS file if it exists, otherwise use RDS if (file.exists(sas_file_path)) { @@ -92,7 +92,7 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { #' path <- system.file("examples", "iris.sas7bdat", package = "haven") #' data_list <- load_data_files(file_paths = path) #' str(data_list) -#' +#' #' @export load_data_files <- function(file_paths) { # Validate input parameters diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 7e92070..36b2e31 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,7 +1,7 @@ # validation (S) vdoc <- local({ # package_name is used # INSIDE # the sourced file below - package_name <- "dv.loader" + package_name <- "dv.loader" utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE) source(utils_file_path, local = TRUE)[["value"]] }) diff --git a/vignettes/integration-guide.Rmd b/vignettes/integration-guide.Rmd index f142d6c..5a38316 100644 --- a/vignettes/integration-guide.Rmd +++ b/vignettes/integration-guide.Rmd @@ -35,9 +35,9 @@ Sys.setenv(RXD_DATA = find.package("dv.loader")) # Load data files from the specified sub-directory of a network file system (NFS) data_list <- dv.loader::load_data( - sub_dir = "extdata/pharmaverseadam", - file_names = c("adsl_sample", "adae_sample"), - print_file_paths = TRUE + sub_dir = "extdata/pharmaverseadam", + file_names = c("adsl_sample", "adae_sample"), + print_file_paths = TRUE ) ``` From 2bbf397e7802579e944da524a2891065511832f3 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 18:15:25 +0800 Subject: [PATCH 22/37] Try to identify issue from tests --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index b84d8c1..331c9c1 100644 --- a/R/utils.R +++ b/R/utils.R @@ -39,7 +39,7 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { if (file_ext == "") { # If no extension is provided, check for both RDS and SAS files - rds_file_name <- paste0(file_name, ".rds") + rds_file_name <- paste0(file_name, ".RDS") sas_file_name <- paste0(file_name, ".sas7bdat") rds_file_path <- file.path(dir_path, rds_file_name) sas_file_path <- file.path(dir_path, sas_file_name) From a02950e21ecb10efb94d17dcfafaae17a83ff13a Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 19:57:31 +0800 Subject: [PATCH 23/37] Use pattern matching to find files when no file extension is provided --- R/utils.R | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/R/utils.R b/R/utils.R index 331c9c1..8b2ad1d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -38,29 +38,41 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { file_ext <- tools::file_ext(file_name) if (file_ext == "") { - # If no extension is provided, check for both RDS and SAS files - rds_file_name <- paste0(file_name, ".RDS") - sas_file_name <- paste0(file_name, ".sas7bdat") - rds_file_path <- file.path(dir_path, rds_file_name) - sas_file_path <- file.path(dir_path, sas_file_name) + # Get all files in the directory + candidates <- basename(list.files(dir_path)) + # Find matching RDS files + rds_match <- grep( + pattern = paste0("^", file_name, "\\.rds$"), + x = candidates, + ignore.case = TRUE, + value = TRUE + ) + + # Find matching SAS files + sas_match <- grep( + pattern = paste0("^", file_name, "\\.sas7bdat$"), + x = candidates, + ignore.case = TRUE, + value = TRUE + ) + + # Prefer SAS file if it exists, otherwise use RDS if (isTRUE(prefer_sas)) { - # Prefer SAS file if it exists, otherwise use RDS - if (file.exists(sas_file_path)) { - return(sas_file_path) - } else if (file.exists(rds_file_path)) { - return(rds_file_path) + if (length(sas_match) > 0) { + return(file.path(dir_path, sas_match[1])) + } else if (length(rds_match) > 0) { + return(file.path(dir_path, rds_match[1])) } else { - stop(dir_path, " does not contain: ", rds_file_name, " or ", sas_file_name) + stop(dir_path, " does not contain SAS or RDS file: ", file_name) } } else if (isFALSE(prefer_sas)) { - # Prefer RDS file if it exists, otherwise use SAS - if (file.exists(rds_file_path)) { - return(rds_file_path) - } else if (file.exists(sas_file_path)) { - return(sas_file_path) + if (length(rds_match) > 0) { + return(file.path(dir_path, rds_match[1])) + } else if (length(sas_match) > 0) { + return(file.path(dir_path, sas_match[1])) } else { - stop(dir_path, " does not contain: ", rds_file_name, " or ", sas_file_name) + stop(dir_path, " does not contain RDS or SAS file: ", file_name) } } } else { From 51ba3ce9bef83c94c617985b6ea35077ba71d091 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 23 Oct 2024 20:04:25 +0800 Subject: [PATCH 24/37] Fix styler issues --- R/utils.R | 6 +++--- man/load_data.Rd | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/R/utils.R b/R/utils.R index 8b2ad1d..17c4e12 100644 --- a/R/utils.R +++ b/R/utils.R @@ -43,7 +43,7 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { # Find matching RDS files rds_match <- grep( - pattern = paste0("^", file_name, "\\.rds$"), + pattern = paste0("^", file_name, "\\.rds$"), x = candidates, ignore.case = TRUE, value = TRUE @@ -51,8 +51,8 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { # Find matching SAS files sas_match <- grep( - pattern = paste0("^", file_name, "\\.sas7bdat$"), - x = candidates, + pattern = paste0("^", file_name, "\\.sas7bdat$"), + x = candidates, ignore.case = TRUE, value = TRUE ) diff --git a/man/load_data.Rd b/man/load_data.Rd index 50f7187..9659710 100644 --- a/man/load_data.Rd +++ b/man/load_data.Rd @@ -24,7 +24,8 @@ load_data( \item{env_var}{[character(1)] The environment variable name for the base directory. Default is "RXD_DATA".} -\item{print_file_paths}{[logical(1)] Logical indicating whether to print the directory path and file names. Default is FALSE.} +\item{print_file_paths}{[logical(1)] Logical indicating whether to print the directory path and file names. +Default is FALSE.} } \value{ A named list of data frames, where each name corresponds to a loaded file. From 6e4a18acbf8f1819c865e471891b1c145441f748 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Fri, 1 Nov 2024 15:41:01 +0800 Subject: [PATCH 25/37] Save demo data to a temp dir --- vignettes/integration-guide.Rmd | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/vignettes/integration-guide.Rmd b/vignettes/integration-guide.Rmd index 5a38316..99cc47f 100644 --- a/vignettes/integration-guide.Rmd +++ b/vignettes/integration-guide.Rmd @@ -27,16 +27,31 @@ pkgs <- c("dv.loader", "dv.manager", "dv.listings") remotes::install_github(repo = paste0("Boehringer-Ingelheim/", pkgs)) ``` +For the purpose of this vignette, we will use the data from the {pharmaverseadam} package and save the `adsl` and `adae` datasets as .sas7bdat files in a temporary directory. + +```{r, eval=FALSE} +# Create a temporary directory +temp_dir <- tempdir() + +# Create a sub-directory for saving the pharmaverseadam data +data_dir <- file.path(temp_dir, "pharmaverseadam") +dir.create(data_dir) + +# Save the adsl and adae datasets to the temporary directory +haven::write_sas(pharmaverseadam::adsl, file.path(data_dir, "adsl.sas7bdat")) +haven::write_sas(pharmaverseadam::adae, file.path(data_dir, "adae.sas7bdat")) +``` + ## Step 1: Load data files ```{r, eval=FALSE} # Set the NFS path as an environment variable -Sys.setenv(RXD_DATA = find.package("dv.loader")) +Sys.setenv(RXD_DATA = temp_dir) # Load data files from the specified sub-directory of a network file system (NFS) data_list <- dv.loader::load_data( - sub_dir = "extdata/pharmaverseadam", - file_names = c("adsl_sample", "adae_sample"), + sub_dir = "pharmaverseadam", + file_names = c("adsl", "adae"), print_file_paths = TRUE ) ``` @@ -48,7 +63,7 @@ data_list <- dv.loader::load_data( module_list <- list( "Data Listings" = dv.listings::mod_listings( module_id = "data_listings", - dataset_names = c("adsl_sample", "adae_sample") + dataset_names = c("adsl", "adae") ) ) ``` @@ -60,7 +75,7 @@ module_list <- list( dv.manager::run_app( data = list("Demo Data" = data_list), module_list = module_list, - filter_data = "adsl_sample", + filter_data = "adsl", title = "DaVinci Application" ) ``` From 89413a77f7b4bdca1d2ceab35e7f3b6c9bc3bf08 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Fri, 1 Nov 2024 15:42:30 +0800 Subject: [PATCH 26/37] Remove pharmaverseadam data from package --- inst/extdata/data.R | 41 ------------------ inst/extdata/pharmaverseadam/adae_sample.rds | Bin 5592 -> 0 bytes .../pharmaverseadam/adae_sample.sas7bdat | Bin 69632 -> 0 bytes inst/extdata/pharmaverseadam/adsl_sample.rds | Bin 2201 -> 0 bytes .../pharmaverseadam/adsl_sample.sas7bdat | Bin 28672 -> 0 bytes 5 files changed, 41 deletions(-) delete mode 100644 inst/extdata/data.R delete mode 100644 inst/extdata/pharmaverseadam/adae_sample.rds delete mode 100644 inst/extdata/pharmaverseadam/adae_sample.sas7bdat delete mode 100644 inst/extdata/pharmaverseadam/adsl_sample.rds delete mode 100644 inst/extdata/pharmaverseadam/adsl_sample.sas7bdat diff --git a/inst/extdata/data.R b/inst/extdata/data.R deleted file mode 100644 index 29c1d03..0000000 --- a/inst/extdata/data.R +++ /dev/null @@ -1,41 +0,0 @@ -# Create directory for pharmaverseadam data if it doesn't exist -data_dir <- file.path("inst", "extdata", "pharmaverseadam") -if (!dir.exists(data_dir)) { - dir.create(data_dir, recursive = TRUE) -} - -# Sample 10 subjects from adsl data -set.seed(123) # For reproducibility -adsl_sample <- pharmaverseadam::adsl |> - dplyr::sample_n(size = 10) - -# Filter adae data for the 10 subjects in adsl_sample -adae_sample <- pharmaverseadam::adae |> - dplyr::filter(USUBJID %in% adsl_sample$USUBJID) - -# Save adsl_sample to rds file -saveRDS( - object = adsl_sample, - file = file.path(data_dir, "adsl_sample.rds") -) - -# Save adae_sample to rds file -saveRDS( - object = adae_sample, - file = file.path(data_dir, "adae_sample.rds") -) - -# Write adsl_sample to sas7bdat file -haven::write_sas( - data = adsl_sample, - path = file.path(data_dir, "adsl_sample.sas7bdat") -) - -# Write adae_sample to sas7bdat file -haven::write_sas( - data = adae_sample, - path = file.path(data_dir, "adae_sample.sas7bdat") -) - -# Add a message to confirm data creation -message("Sample data files have been created in ", data_dir) diff --git a/inst/extdata/pharmaverseadam/adae_sample.rds b/inst/extdata/pharmaverseadam/adae_sample.rds deleted file mode 100644 index f806ce5f2455dcda329ba63dd5458b71127e9414..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5592 zcmV;}6({N+iwFP!000001MOW|Y~)6I=8QBteC&*8JU+&o9ojqVwGp@6>`Ri5SQJUA z>1mN|lC2qefs9)%N}}Cr%4|ww8OV;X39yR|^0L@Ck2W?h0rn+GkRS;V?7ZY*k=>af zF%aYc;(bY8l8qlW$L7IK@n#iS-OW}@Ey)}}^VR>?_1FJb6|1W2xcLA<5F^Cs=ow<< z9B>lnYRW=p2JkKcLM4c^7XUs>j1rRoA7WTuW~zKeRI*gcOL?cBM~t2Yyfd!fxn_M; zZ34%I5c7g;?yT*R{F>S_wRKH30Pi!T;hd$p)OF-8+jwU_N9=Wp)wk+ei=DKNwaiLuCupkXbW8u429q)+}J*(9^@_Z$x7xaqVbyi5rLJ`z1e{;yCAvcL!UD%AyePQrQHhqzu6v>?)g)f2 z$u2!6axAw*dqWdm0-p3dU*VON4!lX0rzNQ@a$dv-xtokA@pLHH7#5m2N`qwIe3KVA z8OwOEyiyevPLP8{ugzCPktONMb-DtAlGU;(SIe|Q%N)=IBXPjN`fcPoFOW`wLULi) z5pg+bMJWf`n&4=OtkS%Iqr1c(msbQvta<~ANqP~^KT`UKLFqZE%(Idx^B(icyvVMQ z3bzEjXr(4aOZ|`?4c6LJm6jA9R2G@z-vp6l@&>Pz0mX;{OG_){A}4_KD!d$)=qb8d zt?-P^B4u9TqDs45rYn^i!wWX^1#+2}Yjnjc@dDs3*1Qsr33N^N>rfAgkJG|Up7X0A zLQa%9nx&aCZd~?NN!`{B6SN{lHMYog-5||Pm892pRimwv+%9NZ{k5ubUSZ0-u;`NK z`e{=WPMh-8F-gyZ96)|Dj)CNgklh>8#fo@?bXrdp)BqV&1Fy)SHQ5b`lxRNGd;)`z zR+H(>cB?;sz~+OEk2If4ezhmjhIGEdFP0Unc5rOCGXWY0g#<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Un zD*Pj|?BXrzjG3#=TWjl{Z2{#vA6ToK^{I8E?md+3=W+hld)vBU8dGcQx9Y~mE#yNp mO0zWXYL3V0wO!Q!172=dZJBNVX%*o0+5ZEBV@J-!*8l***DSRF diff --git a/inst/extdata/pharmaverseadam/adae_sample.sas7bdat b/inst/extdata/pharmaverseadam/adae_sample.sas7bdat deleted file mode 100644 index 28722160375269cf77e12bd2ce35fdac40c42677..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 69632 zcmeG_ZHybobtCB{ourc^$BN@Na=fusS4nj;dAu*#O0;|A-jOknWR^Th=NgdcJL-<< ziM;T5`UupTMU++v{KE*;51>J#qWX~p{!ySt>Y{E!6hULOZmKp0>HtQQ7AcUX3Lq3} z8?;K?_h#Pga+lmYE;q_uk|DsIeKYUP$D4U?=FQhK=KTKZd%t<+Pxs&d_ka1Bezxmt z(H9%>hx`L)+Y? zZj%2)Zf^xC4k!*N4k!*N4k!*N4k!*N4k!*N4*b|T@Za#mNK2lW{|9~^ua4mFlRfiz z$I$k8+t6U&ai`zgo?j;%<)=8X`8lu!w*NEs5KaQX@4I`2%RT8;IX`1!S=xMICNY~zutav+NM#tC$h0h<JKAk)p%QEca#xpcjxI=uUFCFpVxo$N2=VfQ3Ke@$|tTU6CBehvb-% zn6Y>{!JPp(oyg`P;b}O0bHae4Lw?NZ$u!WJCpaE(D+MrB7qccYfjGFLJl5nX?g1|M zuqIP+5uW2PFAp#RT!@9Se5zpbdY%GaO_?)!^Axj;xM>!WnH1m|)-+Zxy3B|dI4E4k z;@O!@!J1`>X-om)oKDO_ek0Kw=U*fWr+x%Kr@4y^!SW!Z&?Oj3o?!X7HHi!YKIaSI zPFg28zbqq@z!%7`f%TIHC~2k>>3qRR0}AAM%7PP4d1I272lI{|mN}KmW}*TgJb)?| z0St@>U%;I}H(y_!zoez+OO<;0Y`IiRRL>R570r0=xmxLbxmYh(D{Q7x{@7|s%dbB7 z(b8PK1sVBQf}qM=Nz1IBd#+St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TV(s zJ%5)oS#J5LX0p7n$Un@9_Zf8#vG?V`4pD00M_Si2TBDHP<+S}E^ot6#za)kZV!rKq(l3(bqBbWLY-Xo<^wgjNrL-Ghb z=W(@sSF$y3c;|8{3*uR46z6i3TmnNkL@r_dKN?FK>GVt-K5Kz%S%*bu8JOgU-wO^_R5%FZ(v(t|OOD ze|b99)?c!={*vN$=H=XS>9+rsT;AjUvV&kLug$=LHSK@f&fxc^OoGCkn(21mR4{C* z@p_{YHW5d5QCL45j>x@b+g_3A}c0QNmZ{_=k{Os8OxXw5p z%r*~(E#^0Y^?`$YO9@ zc))%+^<7S6hWh@WY!W{o?v|~*oa^XKJZC%!kPJ>5Q@VZZJf&uAZSw#MlN9J#Te;}iMjcb~DWC!4o`izI8^Gmhcvr#PTEpg5p7pg5p7pg6D@Iq?7O CR6)D| diff --git a/inst/extdata/pharmaverseadam/adsl_sample.rds b/inst/extdata/pharmaverseadam/adsl_sample.rds deleted file mode 100644 index 35fe401dadf7e9f59eb1dd032dcb23efcaf2e934..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2201 zcmV;K2xj*miwFP!000001MOPNbKAxlheS}6oQKuAPR5>TjihcK)1eB86eT6o4q+0M zm{24GfU$gNRhV2#$dCXFg0_`It?8wm&h(N)ubF8tJ@%MOr@VIBu`d1tdg`^kw9}K_ zT>uO00t-rt8abW>Gve;|*v0RA>=W9(#Bp4POEk&X5R!3`sZiLYSW;e+ifbfG5)q5mD&-}yC{bD)P-|VJSg^0vO`27NZ(LuCH!Q4E zeTj&*R-jm@;cCG*f9`3_;%gnt{MiHu+T`v>pzF>yohNMO31fM}N}e!}C+y-0gLuLc zo-lzYu=6uOGtdfs+Y#IYXb6fR1N)^_QCfvw&7)qqrKj)-%SfYuGzt>ML9s3|bw$`) ziRKg&oOQ@da5hpbdktHrfi+NO)!fKc$kXwql z8&Q?eEwU6uqFPMBc-0?Hn(2b%+WRtsS=P%OddiI>ztpCF+2;IG56UK%2jvGryH240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PWxVU}E8A zM`p~ZX~rk;hvG{*L}nnR^3^D020nI$qn;I+N$)Z<@J(K26+Xyo|29tq(@Q2Y1G8u* z8WZsYMhYh_AN>i({7jfOG4w%{5{dfllqtz?aiX$mdTlYnOFuK_baXP_Ju_wuGc$v~ z)~T+bJ*P5A(nz6WvKMD9aUd5xa zspuG1xN)p-Exc*0W+ZmZ@q2KwO~nK*Y>_f^IBO*z!fIuubD5+yZ&-6FesMXf8IN#G ztXej@n`&m%S9lR?{NX1*pla4QOc^*%ZQ{v<%sI9R;H#>cZ|g4+c_CY2zcgR1M2}-d z>$PU4Va-4>f*;QU-ghQNKFny0?l?^ztgtc44B+7xz$tT@N6+X!v)gKRv{-pO3%43* zs~c{)RB?@L^*H}77I{jUU(KeYV-(C}L*b;uF+_aqc}ryG*{2?)%p?wqj5H2WX4t(6 zJ~je35q~{__v(dtxIq@gttL?ry3*FKZvI6}X2AZE?lV{i#%AE&KO^dq0J!&AE~GKv zWXd$TNqznUs%Efn5y1cim#3Ps1ZAoTauX%V3$|S{!&#SfpNYfXY-$33V$Hx9#hSsp z>Qpx#?afe()ocQm%ajRQ3^?k2-e-F4zk131HG?}!0n}Bysb=Rcz9;r(kN^DvSso&gL&13?kt)#o{&Cu^9WhRE1nHa~P$ih@KhEFkkCu-8Yr^$nQ&UXML z#x;X?n<+|CqtM?Dpx3>mm(0%$>|>_HG%;H<(|WU#nelm`f9|e3MP|PHy?f=Fxn5+X zej8 Date: Wed, 6 Nov 2024 16:19:19 +0800 Subject: [PATCH 27/37] Remove comments inside functions --- R/dvloader.R | 12 ------------ R/utils.R | 14 -------------- 2 files changed, 26 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index 139ea8c..91b7f34 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -19,21 +19,16 @@ #' #' @keywords internal get_base_dir <- function(env_var) { - # Ensure env_var is a single character string checkmate::assert_character(env_var, len = 1) - # Get the value of the environment variable base_dir <- Sys.getenv(env_var) - # Stop if the environment variable is not set if (base_dir == "") { stop("Environment variable ", env_var, " is not set") } - # Ensure the directory exists checkmate::assert_directory_exists(base_dir) - # Return the normalized path return(normalizePath(base_dir)) } @@ -100,36 +95,29 @@ load_data <- function( prefer_sas = FALSE, env_var = "RXD_DATA", print_file_paths = FALSE) { - # Input validation checkmate::assert_character(sub_dir, len = 1, null.ok = TRUE) checkmate::assert_character(file_names, min.len = 1) checkmate::assert_logical(use_wd, len = 1) checkmate::assert_logical(prefer_sas, len = 1) checkmate::assert_character(env_var, len = 1) - # Determine the base directory if (use_wd) { base_dir <- getwd() } else { base_dir <- get_base_dir(env_var = env_var) } - # Construct the full directory path dir_path <- if (is.null(sub_dir)) base_dir else file.path(base_dir, sub_dir) - # Determine the file extension based on preference file_ext <- if (prefer_sas) "sas7bdat" else "rds" - # Get the full file paths file_paths <- get_file_paths(dir_path = dir_path, file_names = file_names, prefer_sas = prefer_sas) - # Print the directory path and file names if requested if (isTRUE(print_file_paths)) { cat("Loading data from", dir_path, "\n") cat("Loading data file(s):", basename(file_paths), "\n") } - # Load the data files data_list <- load_data_files(file_paths) names(data_list) <- file_names diff --git a/R/utils.R b/R/utils.R index 17c4e12..a856cb7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -28,7 +28,6 @@ #' #' @export get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { - # Input validation checkmate::assert_character(dir_path, len = 1) checkmate::assert_character(file_names, min.len = 1) checkmate::assert_logical(prefer_sas, len = 1) @@ -38,10 +37,8 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { file_ext <- tools::file_ext(file_name) if (file_ext == "") { - # Get all files in the directory candidates <- basename(list.files(dir_path)) - # Find matching RDS files rds_match <- grep( pattern = paste0("^", file_name, "\\.rds$"), x = candidates, @@ -49,7 +46,6 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { value = TRUE ) - # Find matching SAS files sas_match <- grep( pattern = paste0("^", file_name, "\\.sas7bdat$"), x = candidates, @@ -57,7 +53,6 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { value = TRUE ) - # Prefer SAS file if it exists, otherwise use RDS if (isTRUE(prefer_sas)) { if (length(sas_match) > 0) { return(file.path(dir_path, sas_match[1])) @@ -76,7 +71,6 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { } } } else { - # If an extension is provided, use the exact file name if (file.exists(file_path)) { return(file_path) } else { @@ -85,7 +79,6 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { } }) - # Normalize all file paths return(normalizePath(unlist(file_paths))) } @@ -107,16 +100,12 @@ get_file_paths <- function(dir_path, file_names, prefer_sas = FALSE) { #' #' @export load_data_files <- function(file_paths) { - # Validate input parameters checkmate::assert_character(file_paths, min.len = 1) checkmate::assert_file_exists(file_paths) - # Read each file and store in a list data_list <- lapply(file_paths, function(file_path) { - # Get file extension extension <- tools::file_ext(file_path) - # Read file based on its extension if (tolower(extension) == "rds") { data <- readRDS(file_path) } else if (tolower(extension) == "sas7bdat") { @@ -125,19 +114,16 @@ load_data_files <- function(file_paths) { stop("Unsupported file extension: ", extension) } - # Get file metadata meta <- file.info(file_path, extra_cols = FALSE) meta[["path"]] <- file_path meta[["file_name"]] <- basename(file_path) - # Add metadata as an attribute to the data rownames(data) <- NULL attr(data, "meta") <- meta return(data) }) - # Set names of the list elements to the basenames of the file paths names(data_list) <- basename(file_paths) return(data_list) From 19ccc3d7fc389ab2e975a69225fb62d6d31a8ded Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 6 Nov 2024 16:53:38 +0800 Subject: [PATCH 28/37] Remvoe get_base_dir() and keep get_nfs_path() --- R/dvloader.R | 65 +++++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index 91b7f34..a539b16 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -1,62 +1,32 @@ -#' Get Base Directory Path +#' Get NFS Base Path from an Environment Variable #' -#' This function retrieves the base directory path from a specified environment variable. -#' It checks if the environment variable is set and if the directory exists. +#' This function assumes that there is an environment variable called `RXD_DATA` +#' which is set to the base path of the NFS directory. #' -#' @param env_var [character(1)] The name of the environment variable containing the base directory path. +#' @return [character(1)] The normalized path to the NFS directory. #' -#' @return [character(1)] The normalized path to the base directory. -#' -#' @examples -#' # Create a temporary directory -#' temp_dir <- tempdir() -#' -#' # Set the BASE_DIR environment variable -#' Sys.setenv(BASE_DIR = temp_dir) -#' -#' # Get the base directory path -#' dv.loader:::get_base_dir("BASE_DIR") -#' -#' @keywords internal -get_base_dir <- function(env_var) { - checkmate::assert_character(env_var, len = 1) - - base_dir <- Sys.getenv(env_var) +#' @export +get_nfs_path <- function() { + base_path <- Sys.getenv("RXD_DATA") - if (base_dir == "") { - stop("Environment variable ", env_var, " is not set") + if (base_path == "") { + stop("Environment variable RXD_DATA must be set") } - checkmate::assert_directory_exists(base_dir) + checkmate::assert_directory_exists(base_path) - return(normalizePath(base_dir)) -} - -#' Get NFS Path -#' -#' This function retrieves the path to the NFS (Network File System) directory. -#' -#' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". -#' -#' @return [character(1)] The path to the NFS directory. -#' -#' @export -get_nfs_path <- function(env_var = "RXD_DATA") { - get_base_dir(env_var = env_var) + return(normalizePath(base_path)) } -#' Get CRE Path +#' Get CRE Base Path from an Environment Variable #' -#' This function retrieves the path to the CRE (Clinical Research Environment) directory. -#' It uses the "RXD_DATA" environment variable as the base directory. +#' This function is an alias for `get_nfs_path()` to maintain backwards compatibility. #' -#' @return [character(1)] The path to the CRE directory. +#' @return [character(1)] The normalized path to the CRE directory. #' #' @export -get_cre_path <- function() { - get_base_dir(env_var = "RXD_DATA") -} +get_cre_path <- get_nfs_path #' Load Data Files @@ -68,7 +38,6 @@ get_cre_path <- function() { #' @param file_names [character(1+)] Character vector of file names to load (without extension). #' @param use_wd [logical(1)] Logical indicating whether to use the current working directory. Default is FALSE. #' @param prefer_sas [logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE. -#' @param env_var [character(1)] The environment variable name for the base directory. Default is "RXD_DATA". #' @param print_file_paths [logical(1)] Logical indicating whether to print the directory path and file names. #' Default is FALSE. #' @@ -93,18 +62,16 @@ load_data <- function( file_names, use_wd = FALSE, prefer_sas = FALSE, - env_var = "RXD_DATA", print_file_paths = FALSE) { checkmate::assert_character(sub_dir, len = 1, null.ok = TRUE) checkmate::assert_character(file_names, min.len = 1) checkmate::assert_logical(use_wd, len = 1) checkmate::assert_logical(prefer_sas, len = 1) - checkmate::assert_character(env_var, len = 1) if (use_wd) { base_dir <- getwd() } else { - base_dir <- get_base_dir(env_var = env_var) + base_dir <- get_nfs_path() } dir_path <- if (is.null(sub_dir)) base_dir else file.path(base_dir, sub_dir) From d164c100f7fe40ec005f787c7e6e2bed87358fce Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 6 Nov 2024 17:41:54 +0800 Subject: [PATCH 29/37] Update function docs --- R/dvloader.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index a539b16..de19181 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -1,9 +1,9 @@ -#' Get NFS Base Path from an Environment Variable +#' Get Base Path from an Environment Variable #' #' This function assumes that there is an environment variable called `RXD_DATA` -#' which is set to the base path of the NFS directory. +#' which is set to the base path of the data directory. #' -#' @return [character(1)] The normalized path to the NFS directory. +#' @return [character(1)] The normalized base path. #' #' @export get_nfs_path <- function() { @@ -18,12 +18,11 @@ get_nfs_path <- function() { return(normalizePath(base_path)) } - -#' Get CRE Base Path from an Environment Variable +#' Get Base Path from an Environment Variable #' #' This function is an alias for `get_nfs_path()` to maintain backwards compatibility. #' -#' @return [character(1)] The normalized path to the CRE directory. +#' @return [character(1)] The normalized base path. #' #' @export get_cre_path <- get_nfs_path From 912957f270779303963d69e8658e8e3ca1b311a9 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 6 Nov 2024 17:43:08 +0800 Subject: [PATCH 30/37] Update examples in README --- README.md | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index ab3eadc..c90a943 100644 --- a/README.md +++ b/README.md @@ -25,50 +25,30 @@ remotes::install_github("Boehringer-Ingelheim/dv.loader") ## Examples -The main function is `dv.loader::load_data()`, which loads data files from sub-directories of a network file system (NFS) or the working directory. +The `dv.loader` package provides two main functions for loading data: -### Example 1: Sub-directory of Network File System (NFS) +1. `load_data_files()`: A flexible function that loads multiple data files from any specified file paths, regardless of whether they are in the same directory or not. -To load data files from a NFS, you need to set the NFS path as an environment variable. By default, the environment variable name is `RXD_DATA`. +2. `load_data()`: A convenience wrapper around `load_data_files()` that simplifies loading multiple files from a single sub-directory of a base path. -You can run the following command to check the NFS path if it is already set. +### Example 1: `load_data_files()` ```r -# Check the NFS path -dv.loader::get_nfs_path() -``` - -If the NFS path is not set, you can set it by running the following command. - -```r -# Set the NFS path as an environment variable -Sys.setenv(RXD_DATA = "path/to/network-file-system") -``` - -The environment variable setup is not needed if you have already set the NFS path as an environment variable in your `.Renviron` or `.Rprofile` file. - -If the NFS path has been properly set, you can load data files from the NFS and its sub-directories. - -```r -# Load data files from the specified sub-directory of a network file system (NFS) -dv.loader::load_data( - sub_dir = "sub-directory/of/network-file-system", - file_names = c("adsl.sas7bdat", "adae.sas7bdat") +# Load data files from the specified file paths +dv.loader::load_data_files( + file_paths = c("path/to/adsl.sas7bdat", "path/to/adae.sas7bdat") ) ``` -For the `file_names` argument, it is recommended to use the full file names including the file extension. - -### Example 2: Sub-directory of the Working Directory +### Example 2: `load_data()` -To load data files from a local directory, there is no need to set an environment variable. You use `use_wd = TRUE` to indicate that the data files are loaded from a sub-directory of the working directory. +In order to use `load_data()`, you need to set the base path as an environment variable called `RXD_DATA`. ```r -# Load data files from the specified sub-directory of the working directory +# Load data files from the specified sub-directory of a base path dv.loader::load_data( - sub_dir = "sub-directory/of/working-directory", - file_names = c("adsl.sas7bdat", "adae.sas7bdat"), - use_wd = TRUE + sub_dir = "sub-directory/of/base-path", + file_names = c("adsl.sas7bdat", "adae.sas7bdat") ) ``` From 52d058bd1817e160e90858ece0849cfebd4bc0b2 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 6 Nov 2024 17:43:32 +0800 Subject: [PATCH 31/37] Update example in vignettes --- vignettes/integration-guide.Rmd | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/vignettes/integration-guide.Rmd b/vignettes/integration-guide.Rmd index 99cc47f..d7d36f5 100644 --- a/vignettes/integration-guide.Rmd +++ b/vignettes/integration-guide.Rmd @@ -45,14 +45,9 @@ haven::write_sas(pharmaverseadam::adae, file.path(data_dir, "adae.sas7bdat")) ## Step 1: Load data files ```{r, eval=FALSE} -# Set the NFS path as an environment variable -Sys.setenv(RXD_DATA = temp_dir) - -# Load data files from the specified sub-directory of a network file system (NFS) -data_list <- dv.loader::load_data( - sub_dir = "pharmaverseadam", - file_names = c("adsl", "adae"), - print_file_paths = TRUE +# Load data files from the specified file paths +data_list <- dv.loader::load_data_files( + file_paths = file.path(data_dir, c("adsl.sas7bdat", "adae.sas7bdat")) ) ``` @@ -63,7 +58,7 @@ data_list <- dv.loader::load_data( module_list <- list( "Data Listings" = dv.listings::mod_listings( module_id = "data_listings", - dataset_names = c("adsl", "adae") + dataset_names = c("adsl.sas7bdat", "adae.sas7bdat") ) ) ``` @@ -75,7 +70,7 @@ module_list <- list( dv.manager::run_app( data = list("Demo Data" = data_list), module_list = module_list, - filter_data = "adsl", + filter_data = "adsl.sas7bdat", title = "DaVinci Application" ) ``` From c06a26a9b90826be9c98612d2f9d74c45a5d81f0 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 6 Nov 2024 17:44:44 +0800 Subject: [PATCH 32/37] Update R document files --- man/get_base_dir.Rd | 30 ------------------------------ man/get_cre_path.Rd | 7 +++---- man/get_nfs_path.Rd | 12 +++++------- man/load_data.Rd | 3 --- 4 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 man/get_base_dir.Rd diff --git a/man/get_base_dir.Rd b/man/get_base_dir.Rd deleted file mode 100644 index 891d825..0000000 --- a/man/get_base_dir.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dvloader.R -\name{get_base_dir} -\alias{get_base_dir} -\title{Get Base Directory Path} -\usage{ -get_base_dir(env_var) -} -\arguments{ -\item{env_var}{[character(1)] The name of the environment variable containing the base directory path.} -} -\value{ -[character(1)] The normalized path to the base directory. -} -\description{ -This function retrieves the base directory path from a specified environment variable. -It checks if the environment variable is set and if the directory exists. -} -\examples{ -# Create a temporary directory -temp_dir <- tempdir() - -# Set the BASE_DIR environment variable -Sys.setenv(BASE_DIR = temp_dir) - -# Get the base directory path -dv.loader:::get_base_dir("BASE_DIR") - -} -\keyword{internal} diff --git a/man/get_cre_path.Rd b/man/get_cre_path.Rd index 03686b2..897a61c 100644 --- a/man/get_cre_path.Rd +++ b/man/get_cre_path.Rd @@ -2,14 +2,13 @@ % Please edit documentation in R/dvloader.R \name{get_cre_path} \alias{get_cre_path} -\title{Get CRE Path} +\title{Get Base Path from an Environment Variable} \usage{ get_cre_path() } \value{ -[character(1)] The path to the CRE directory. +[character(1)] The normalized base path. } \description{ -This function retrieves the path to the CRE (Clinical Research Environment) directory. -It uses the "RXD_DATA" environment variable as the base directory. +This function is an alias for `get_nfs_path()` to maintain backwards compatibility. } diff --git a/man/get_nfs_path.Rd b/man/get_nfs_path.Rd index 3c4ba73..516256b 100644 --- a/man/get_nfs_path.Rd +++ b/man/get_nfs_path.Rd @@ -2,16 +2,14 @@ % Please edit documentation in R/dvloader.R \name{get_nfs_path} \alias{get_nfs_path} -\title{Get NFS Path} +\title{Get Base Path from an Environment Variable} \usage{ -get_nfs_path(env_var = "RXD_DATA") -} -\arguments{ -\item{env_var}{[character(1)] The environment variable name for the base directory. Default is "RXD_DATA".} +get_nfs_path() } \value{ -[character(1)] The path to the NFS directory. +[character(1)] The normalized base path. } \description{ -This function retrieves the path to the NFS (Network File System) directory. +This function assumes that there is an environment variable called `RXD_DATA` +which is set to the base path of the data directory. } diff --git a/man/load_data.Rd b/man/load_data.Rd index 9659710..2342a61 100644 --- a/man/load_data.Rd +++ b/man/load_data.Rd @@ -9,7 +9,6 @@ load_data( file_names, use_wd = FALSE, prefer_sas = FALSE, - env_var = "RXD_DATA", print_file_paths = FALSE ) } @@ -22,8 +21,6 @@ load_data( \item{prefer_sas}{[logical(1)] Logical indicating whether to prefer SAS7BDAT files over RDS. Default is FALSE.} -\item{env_var}{[character(1)] The environment variable name for the base directory. Default is "RXD_DATA".} - \item{print_file_paths}{[logical(1)] Logical indicating whether to print the directory path and file names. Default is FALSE.} } From b8d3bc3a18953e67d975569c06d7c7164268cba3 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 6 Nov 2024 17:56:38 +0800 Subject: [PATCH 33/37] Fix styler issues --- R/dvloader.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index de19181..6ae0044 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -1,6 +1,6 @@ #' Get Base Path from an Environment Variable #' -#' This function assumes that there is an environment variable called `RXD_DATA` +#' This function assumes that there is an environment variable called `RXD_DATA` #' which is set to the base path of the data directory. #' #' @return [character(1)] The normalized base path. @@ -20,7 +20,7 @@ get_nfs_path <- function() { #' Get Base Path from an Environment Variable #' -#' This function is an alias for `get_nfs_path()` to maintain backwards compatibility. +#' This function is an alias for `get_nfs_path()` to maintain backwards compatibility. #' #' @return [character(1)] The normalized base path. #' From abe10d67aca9bcabab78944b98c5a5f7c448614d Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 13 Nov 2024 14:09:02 +0800 Subject: [PATCH 34/37] Check argument print_file_paths --- R/dvloader.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/dvloader.R b/R/dvloader.R index 6ae0044..82327c6 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -66,6 +66,7 @@ load_data <- function( checkmate::assert_character(file_names, min.len = 1) checkmate::assert_logical(use_wd, len = 1) checkmate::assert_logical(prefer_sas, len = 1) + checkmate::assert_logical(print_file_paths, len = 1) if (use_wd) { base_dir <- getwd() From cf48a948f09bae10c5bd80bf5791a88dda816db0 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 13 Nov 2024 14:10:42 +0800 Subject: [PATCH 35/37] Remove unused code --- R/dvloader.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/dvloader.R b/R/dvloader.R index 82327c6..c032317 100644 --- a/R/dvloader.R +++ b/R/dvloader.R @@ -76,8 +76,6 @@ load_data <- function( dir_path <- if (is.null(sub_dir)) base_dir else file.path(base_dir, sub_dir) - file_ext <- if (prefer_sas) "sas7bdat" else "rds" - file_paths <- get_file_paths(dir_path = dir_path, file_names = file_names, prefer_sas = prefer_sas) if (isTRUE(print_file_paths)) { From 6dc6e0ea18920904284ac1956130a3d29a9f10b7 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 13 Nov 2024 14:25:46 +0800 Subject: [PATCH 36/37] Updated changelog --- NEWS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index e3df5dc..fbc1679 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,10 @@ # dv.loader 2.1.0 -- Refactored code to improve readability and maintainability. +- Introduced new `load_data_files()` function that provides flexible loading of data files from any file paths. -- Fixed issue of partial matching when the `file_names` argument contains no file extensions. +- Updated `load_data()` function to serve as a convenience wrapper around `load_data_files()` for loading files from a single directory. -- Added arguments `env_var` and `print_file_paths` in `load_data()` function to provide more flexibility and control. +- Added `print_file_paths` option to `load_data()` to display the full paths of loaded files, helping users identify potential file name matching issues. # dv.loader 2.0.0 From a14c5003b5438ad00169c6a6403a59920030f20d Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Wed, 13 Nov 2024 14:37:19 +0800 Subject: [PATCH 37/37] Update Rd file --- man/get_nfs_path.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/get_nfs_path.Rd b/man/get_nfs_path.Rd index 516256b..4d331fe 100644 --- a/man/get_nfs_path.Rd +++ b/man/get_nfs_path.Rd @@ -10,6 +10,6 @@ get_nfs_path() [character(1)] The normalized base path. } \description{ -This function assumes that there is an environment variable called `RXD_DATA` +This function assumes that there is an environment variable called `RXD_DATA` which is set to the base path of the data directory. }