diff --git a/DESCRIPTION b/DESCRIPTION index f2a6b4c..20f3a22 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,9 @@ Imports: DSI (>= 1.7.0), cli, rlang, - assertthat + assertthat, + dplyr, + purrr Suggests: testthat (>= 3.0.0), knitr, @@ -39,8 +41,7 @@ Suggests: DSLite, dsBase, dsBaseClient, - dsTidyverse, - dplyr + dsTidyverse Config/testthat/edition: 3 Additional_repositories: https://cran.obiba.org/ VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 21e6b16..2de37f4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(ds.mutate) export(ds.rename) export(ds.select) export(ds.slice) +export(ds.tidy_fill) export(ds.ungroup) import(dplyr) import(purrr) @@ -22,14 +23,16 @@ importFrom(DSI,datashield.assign) importFrom(DSI,datashield.connections_find) importFrom(assertthat,assert_that) importFrom(cli,cli_abort) +importFrom(cli,cli_alert_danger) importFrom(cli,cli_alert_info) +importFrom(cli,cli_alert_success) +importFrom(cli,cli_alert_warning) +importFrom(cli,cli_end) +importFrom(cli,cli_li) importFrom(cli,cli_ol) -importFrom(dplyr,"%>%") -importFrom(methods,is) -importFrom(purrr,imap_chr) +importFrom(cli,cli_text) +importFrom(cli,cli_ul) importFrom(purrr,map) -importFrom(purrr,map_chr) -importFrom(purrr,map_int) -importFrom(purrr,map_lgl) +importFrom(rlang,enquo) importFrom(rlang,quo_text) importFrom(rlang,sym) diff --git a/R/ds.tidy_fill.R b/R/ds.tidy_fill.R index 4241ee7..74fc745 100644 --- a/R/ds.tidy_fill.R +++ b/R/ds.tidy_fill.R @@ -10,8 +10,7 @@ #' @import dplyr #' @import purrr #' @return The filled DataFrame with added columns and adjusted classes or factor levels. -#' @examples -#' ds.tidy_fill(df.name = "df1", newobj = "filled_df", datasources = conns) +#' @export ds.tidy_fill <- function(df.name = NULL, newobj = NULL, datasources = NULL) { datasources <- .set_datasources(datasources) @@ -62,6 +61,7 @@ ds.tidy_fill <- function(df.name = NULL, newobj = NULL, datasources = NULL) { #' @param col_names A list of column names from different data sources. #' @return None. Throws an error if columns are identical. #' @importFrom cli cli_abort +#' @noRd .stop_if_cols_identical <- function(col_names) { are_identical <- all(sapply(col_names, identical, col_names[[1]])) if (are_identical) { @@ -77,6 +77,7 @@ ds.tidy_fill <- function(df.name = NULL, newobj = NULL, datasources = NULL) { #' @param datasources Data sources from which to aggregate data. #' @return A DataFrame containing the variable classes from each data source. #' @import dplyr +#' @noRd .get_var_classes <- function(df.name, datasources) { cally <- call("classAllColsDS", df.name) classes <- datashield.aggregate(datasources, cally) %>% @@ -92,7 +93,9 @@ ds.tidy_fill <- function(df.name = NULL, newobj = NULL, datasources = NULL) { #' @return A list of variables that have class conflicts. #' @import dplyr #' @importFrom purrr map +#' @noRd .identify_class_conflicts <- function(classes) { + server <- NULL different_class <- classes |> dplyr::select(-server) |> map(~ unique(na.omit(.))) @@ -109,6 +112,7 @@ ds.tidy_fill <- function(df.name = NULL, newobj = NULL, datasources = NULL) { #' @param all_servers The names of all servers. #' @param all_classes The classes of the variables across servers. #' @return A vector of decisions for each variable's class. +#' @noRd prompt_user_class_decision_all_vars <- function(vars, all_servers, all_classes) { decisions <- c() for (i in 1:length(vars)) { @@ -124,7 +128,9 @@ prompt_user_class_decision_all_vars <- function(vars, all_servers, all_classes) #' @param var The variable name with a class conflict. #' @param all_servers The names of all servers. #' @param all_classes The classes of the variable across servers. +#' @importFrom cli cli_alert_warning cli_alert_danger #' @return A decision for the variable's class. +#' @noRd prompt_user_class_decision <- function(var, all_servers, all_classes) { cli_alert_warning("`ds.dataFrameFill` requires that all columns have the same class.") cli_alert_danger("Column {.strong {var}} has following classes:") @@ -139,7 +145,9 @@ prompt_user_class_decision <- function(var, all_servers, all_classes) { #' #' @param answer The user's input. #' @param var The variable name. +#' @importFrom cli cli_abort cli_alert_warning cli_alert_info #' @return The user's decision or a recursive prompt for input. +#' @noRd check_response_class <- function(answer, var) { if (answer == "6") { cli_abort("Aborted `ds.dataFrameFill`", .call = NULL) @@ -158,9 +166,10 @@ check_response_class <- function(answer, var) { #' #' @param question The question to ask the user. #' @return The user's decision. +#' @noRd ask_question_wait_response_class <- function(var) { ask_question(var) - answer <- readLine() + answer <- readline() return(check_response_class(answer, var)) } @@ -175,6 +184,7 @@ ask_question_wait_response_class <- function(var) { #' @return None. This function is used for prompting the user and does not return a value. #' @examples #' ask_question("variable_name") +#' @noRd ask_question <- function(var) { cli_alert_info("Would you like to:") class_options <- c("a factor", "an integer", "numeric", "a character", "a logical vector") @@ -194,6 +204,7 @@ ask_question <- function(var) { #' @param newobj The name of the new DataFrame. #' @param datasources Data sources from which to aggregate data. #' @return None. Updates the DataFrame with consistent variable classes. +#' @noRd .fix_classes <- function(df.name, different_classes, class_decisions, newobj, datasources) { cally <- call("fixClassDS", df.name, names(different_classes), class_decisions) datashield.assign(datasources, newobj, cally) @@ -205,6 +216,7 @@ ask_question <- function(var) { #' #' @param col_names A list of column names. #' @return A vector of unique column names. +#' @noRd .get_unique_cols <- function(col_names) { return( unique( @@ -222,6 +234,7 @@ ask_question <- function(var) { #' @param newobj The name of the new DataFrame. #' @param datasources Data sources from which to aggregate data. #' @return None. Updates the DataFrame with added columns. +#' @noRd .add_missing_cols_to_df <- function(df.name, unique_cols, newobj, datasources) { cally <- call("makeColsSameDS", df.name, unique_cols) datashield.assign(datasources, newobj, cally) @@ -235,6 +248,7 @@ ask_question <- function(var) { #' @param datasources Data sources from which to aggregate data. #' @param col_names A list of column names. #' @return A list of added columns. +#' @noRd .summarise_new_cols <- function(newobj, datasources, col_names) { new_names <- datashield.aggregate(datasources, call("colnamesDS", newobj)) return(.get_added_cols(col_names, new_names)) @@ -247,6 +261,7 @@ ask_question <- function(var) { #' @param old_names A list of old column names. #' @param new_names A list of new column names. #' @return A list of added column names. +#' @noRd .get_added_cols <- function(old_names, new_names) { list(old_names, new_names) %>% pmap(function(.x, .y) { @@ -260,6 +275,7 @@ ask_question <- function(var) { #' #' @param var_classes A DataFrame containing variable classes. #' @return A vector of factor variables. +#' @noRd .identify_factor_vars <- function(var_classes) { return( var_classes %>% @@ -276,6 +292,7 @@ ask_question <- function(var) { #' @param newobj The name of the new DataFrame. #' @param datasources Data sources from which to aggregate data. #' @return A list of factor levels. +#' @noRd .get_factor_levels <- function(factor_vars, newobj, datasources) { cally <- call("getAllLevelsDS", newobj, names(factor_vars)) return(datashield.aggregate(datasources, cally)) @@ -287,6 +304,7 @@ ask_question <- function(var) { #' #' @param factor_levels A list of factor levels. #' @return A list of variables with level conflicts. +#' @noRd .identify_level_conflicts <- function(factor_levels) { levels <- factor_levels %>% pmap_lgl(function(...) { @@ -303,6 +321,7 @@ ask_question <- function(var) { #' #' @param level_conflicts A list of variables with factor level conflicts. #' @return The user's decision. +#' @noRd ask_question_wait_response_levels <- function(level_conflicts) { .make_levels_message(level_conflicts) answer <- readline() @@ -314,7 +333,9 @@ ask_question_wait_response_levels <- function(level_conflicts) { #' Creates a message to alert the user about factor level conflicts and prompt for action. #' #' @param level_conflicts A list of variables with factor level conflicts. +#' @importFrom cli cli_alert_warning cli_alert_info cli_ol #' @return None. Prints the message to the console. +#' @noRd .make_levels_message <- function(level_conflicts) { cli_alert_warning("Warning: factor variables {level_conflicts} do not have the same levels in all studies") cli_alert_info("Would you like to:") @@ -328,6 +349,7 @@ ask_question_wait_response_levels <- function(level_conflicts) { #' @param answer The user's input. #' @param level_conflicts A list of variables with factor level conflicts. #' @return The user's decision. +#' @noRd check_response_levels <- function(answer, level_conflicts) { if (!answer %in% as.character(1:2)) { cli_alert_warning("Invalid input. Please try again.") @@ -345,6 +367,7 @@ check_response_levels <- function(answer, level_conflicts) { #' @param factor_levels A list of factor levels. #' @param level_conflicts A list of variables with level conflicts. #' @return A list of unique factor levels. +#' @noRd .get_unique_levels <- function(factor_levels, level_conflicts) { unique_levels <- factor_levels %>% map(~ .[level_conflicts]) %>% @@ -363,6 +386,7 @@ check_response_levels <- function(answer, level_conflicts) { #' @param unique_levels A list of unique factor levels. #' @param datasources Data sources from which to aggregate data. #' @return None. Updates the DataFrame with the new factor levels. +#' @noRd .set_factor_levels <- function(newobj, unique_levels, datasources) { cally <- call("setAllLevelsDS", newobj, names(unique_levels), unique_levels) datashield.assign(datasources, newobj, cally) @@ -379,7 +403,9 @@ check_response_levels <- function(answer, level_conflicts) { #' @param level_conflicts A list of variables with level conflicts. #' @param levels_decision The decision made regarding factor levels. #' @param newobj The name of the new DataFrame. +#' @importFrom cli cli_text #' @return None. Prints messages to the console. +#' @noRd .print_out_messages <- function(added_cols, class_decisions, different_classes, unique_levels, level_conflicts, levels_decision, newobj) { .print_var_recode_message(added_cols, newobj) @@ -400,7 +426,9 @@ check_response_levels <- function(answer, level_conflicts) { #' #' @param added_cols A list of added columns. #' @param newobj The name of the new DataFrame. +#' @importFrom cli cli_text #' @return None. Prints the message to the console. +#' @noRd .print_var_recode_message <- function(added_cols, newobj) { cli_alert_success("The following variables have been added to {newobj}:") added_cols_neat <- added_cols %>% map(~ ifelse(length(.) == 0, "", .)) @@ -418,7 +446,9 @@ check_response_levels <- function(answer, level_conflicts) { #' @param class_decisions A vector of class decisions. #' @param different_classes A list of variables with class conflicts. #' @param newobj The name of the new DataFrame. +#' @importFrom cli cli_alert_info cli_alert_success #' @return None. Prints the message to the console. +#' @noRd .print_class_recode_message <- function(class_decisions, different_classes, newobj) { choice_neat <- change_choice_to_string(class_decisions) class_message <- paste0(names(different_classes), " --> ", choice_neat) @@ -434,7 +464,9 @@ check_response_levels <- function(answer, level_conflicts) { #' #' @param unique_levels A list of unique factor levels. #' @param newobj The name of the new DataFrame. +#' @importFrom cli cli_alert_success cli_alert_info #' @return None. Prints the message to the console. +#' @noRd .print_levels_recode_message <- function(unique_levels, newobj) { levels_message <- .make_levels_recode_message(unique_levels) cli_alert_success("The following levels have been set in {newobj}: ") @@ -449,6 +481,7 @@ check_response_levels <- function(answer, level_conflicts) { #' #' @param unique_levels A list of unique factor levels. #' @return A formatted string summarizing the level recoding. +#' @noRd .make_levels_recode_message <- function(unique_levels) { return( list(names(unique_levels), unique_levels) %>% @@ -458,28 +491,42 @@ check_response_levels <- function(answer, level_conflicts) { ) } +#' Convert Class Decision Code to String +#' +#' This function converts a numeric class decision input (represented as a string) +#' into the corresponding class type string (e.g., "factor", "integer", "numeric", etc.). +#' @param class_decision A string representing the class decision. It should be +#' one of the following values: "1", "2", "3", "4", or "5". +#' @return A string representing the class type corresponding to the input: +#' "factor", "integer", "numeric", "character", or "logical". +#' @noRd +change_choice_to_string <- function(class_decision) { + case_when( + class_decision == "1" ~ "factor", + class_decision == "2" ~ "integer", + class_decision == "3" ~ "numeric", + class_decision == "4" ~ "character", + class_decision == "5" ~ "logical" + ) +} - - - -# change_choice_to_string <- function(class_decision) { -# case_when( -# class_decision == "1" ~ "factor", -# class_decision == "2" ~ "integer", -# class_decision == "3" ~ "numeric", -# class_decision == "4" ~ "character", -# class_decision == "5" ~ "logical" -# ) -# } - -# print_all_classes <- function(all_servers, all_classes) { -# combined <- paste(all_servers, all_classes, sep = ": ") -# cli_ul() -# for (i in 1:length(combined)) { -# cli_li("{combined[i]}") -# } -# cli_end() -# } - - - +#' Print All Server-Class Pairs +#' +#' This function prints out a list of server names along with their corresponding +#' class types. It formats the output with a bullet-point list using the `cli` package. +#' +#' @param all_servers A character vector containing the names of servers. +#' @param all_classes A character vector containing the class types corresponding +#' to each server. +#' @return This function does not return a value. It prints the server-class pairs +#' to the console as a bulleted list. +#' @importFrom cli cli_ul cli_li cli_end +#' @noRd +print_all_classes <- function(all_servers, all_classes) { + combined <- paste(all_servers, all_classes, sep = ": ") + cli_ul() + for (i in 1:length(combined)) { + cli_li("{combined[i]}") + } + cli_end() +} diff --git a/man/ask_question.Rd b/man/ask_question.Rd deleted file mode 100644 index b1b252b..0000000 --- a/man/ask_question.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{ask_question} -\alias{ask_question} -\title{Prompt User for Class Conversion Options} -\usage{ -ask_question(var) -} -\arguments{ -\item{var}{The name of the variable for which the user is prompted to select a class conversion option.} -} -\value{ -None. This function is used for prompting the user and does not return a value. -} -\description{ -This function prompts the user with options to convert a variable to a specific class (e.g., factor, integer, numeric, character, or logical). -The function provides a list of class conversion options for the specified variable and includes an option to cancel the operation. -} -\examples{ -ask_question("variable_name") -} diff --git a/man/ask_question_wait_response_class.Rd b/man/ask_question_wait_response_class.Rd deleted file mode 100644 index d146005..0000000 --- a/man/ask_question_wait_response_class.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{ask_question_wait_response_class} -\alias{ask_question_wait_response_class} -\title{Ask Question and Wait for Class Response} -\usage{ -ask_question_wait_response_class(var) -} -\arguments{ -\item{question}{The question to ask the user.} -} -\value{ -The user's decision. -} -\description{ -Prompts the user with a question and waits for a response related to class decisions. -} diff --git a/man/ask_question_wait_response_levels.Rd b/man/ask_question_wait_response_levels.Rd deleted file mode 100644 index 7ffb022..0000000 --- a/man/ask_question_wait_response_levels.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{ask_question_wait_response_levels} -\alias{ask_question_wait_response_levels} -\title{Ask Question and Wait for Response on Factor Levels} -\usage{ -ask_question_wait_response_levels(level_conflicts) -} -\arguments{ -\item{level_conflicts}{A list of variables with factor level conflicts.} -} -\value{ -The user's decision. -} -\description{ -Prompts the user with options for resolving factor level conflicts and waits for a response. -} diff --git a/man/check_response_class.Rd b/man/check_response_class.Rd deleted file mode 100644 index e49e0c7..0000000 --- a/man/check_response_class.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{check_response_class} -\alias{check_response_class} -\title{Check User Response for Class Decision} -\usage{ -check_response_class(answer, var) -} -\arguments{ -\item{answer}{The user's input.} - -\item{var}{The variable name.} -} -\value{ -The user's decision or a recursive prompt for input. -} -\description{ -Checks the user's input to ensure it is valid for class decisions. -} diff --git a/man/check_response_levels.Rd b/man/check_response_levels.Rd deleted file mode 100644 index 77061a0..0000000 --- a/man/check_response_levels.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{check_response_levels} -\alias{check_response_levels} -\title{Check User Response for Factor Levels} -\usage{ -check_response_levels(answer, level_conflicts) -} -\arguments{ -\item{answer}{The user's input.} - -\item{level_conflicts}{A list of variables with factor level conflicts.} -} -\value{ -The user's decision. -} -\description{ -Checks the user's input to ensure it is valid for resolving factor level conflicts. -} diff --git a/man/dot-add_missing_cols_to_df.Rd b/man/dot-add_missing_cols_to_df.Rd deleted file mode 100644 index 3f0a1c4..0000000 --- a/man/dot-add_missing_cols_to_df.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.add_missing_cols_to_df} -\alias{.add_missing_cols_to_df} -\title{Add Missing Columns to DataFrame} -\usage{ -.add_missing_cols_to_df(df.name, unique_cols, newobj, datasources) -} -\arguments{ -\item{df.name}{The name of the DataFrame.} - -\item{unique_cols}{A vector of unique column names.} - -\item{newobj}{The name of the new DataFrame.} - -\item{datasources}{Data sources from which to aggregate data.} -} -\value{ -None. Updates the DataFrame with added columns. -} -\description{ -Adds any missing columns to the DataFrame to ensure all columns are present across data sources. -} diff --git a/man/dot-fix_classes.Rd b/man/dot-fix_classes.Rd deleted file mode 100644 index 7e7fc07..0000000 --- a/man/dot-fix_classes.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.fix_classes} -\alias{.fix_classes} -\title{Fix Variable Classes} -\usage{ -.fix_classes(df.name, different_classes, class_decisions, newobj, datasources) -} -\arguments{ -\item{df.name}{The name of the DataFrame.} - -\item{different_classes}{A list of variables with class conflicts.} - -\item{class_decisions}{The decisions made by the user.} - -\item{newobj}{The name of the new DataFrame.} - -\item{datasources}{Data sources from which to aggregate data.} -} -\value{ -None. Updates the DataFrame with consistent variable classes. -} -\description{ -Applies the user's class decisions to fix the classes of variables across different data sources. -} diff --git a/man/dot-get_added_cols.Rd b/man/dot-get_added_cols.Rd deleted file mode 100644 index 1fa8598..0000000 --- a/man/dot-get_added_cols.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.get_added_cols} -\alias{.get_added_cols} -\title{Get Added Columns} -\usage{ -.get_added_cols(old_names, new_names) -} -\arguments{ -\item{old_names}{A list of old column names.} - -\item{new_names}{A list of new column names.} -} -\value{ -A list of added column names. -} -\description{ -Compares the old and new column names and identifies newly added columns. -} diff --git a/man/dot-get_factor_levels.Rd b/man/dot-get_factor_levels.Rd deleted file mode 100644 index 6709b35..0000000 --- a/man/dot-get_factor_levels.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.get_factor_levels} -\alias{.get_factor_levels} -\title{Get Factor Levels from Data Sources} -\usage{ -.get_factor_levels(factor_vars, newobj, datasources) -} -\arguments{ -\item{factor_vars}{A vector of factor variables.} - -\item{newobj}{The name of the new DataFrame.} - -\item{datasources}{Data sources from which to aggregate data.} -} -\value{ -A list of factor levels. -} -\description{ -Retrieves the levels of factor variables from different data sources. -} diff --git a/man/dot-get_unique_cols.Rd b/man/dot-get_unique_cols.Rd deleted file mode 100644 index 084b048..0000000 --- a/man/dot-get_unique_cols.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.get_unique_cols} -\alias{.get_unique_cols} -\title{Get Unique Columns from Data Sources} -\usage{ -.get_unique_cols(col_names) -} -\arguments{ -\item{col_names}{A list of column names.} -} -\value{ -A vector of unique column names. -} -\description{ -Retrieves all unique columns from the data sources. -} diff --git a/man/dot-get_unique_levels.Rd b/man/dot-get_unique_levels.Rd deleted file mode 100644 index cd8f819..0000000 --- a/man/dot-get_unique_levels.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.get_unique_levels} -\alias{.get_unique_levels} -\title{Get Unique Factor Levels} -\usage{ -.get_unique_levels(factor_levels, level_conflicts) -} -\arguments{ -\item{factor_levels}{A list of factor levels.} - -\item{level_conflicts}{A list of variables with level conflicts.} -} -\value{ -A list of unique factor levels. -} -\description{ -Retrieves the unique factor levels for variables with conflicts. -} diff --git a/man/dot-get_var_classes.Rd b/man/dot-get_var_classes.Rd deleted file mode 100644 index a5e5c41..0000000 --- a/man/dot-get_var_classes.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.get_var_classes} -\alias{.get_var_classes} -\title{Get Variable Classes from DataFrame} -\usage{ -.get_var_classes(df.name, datasources) -} -\arguments{ -\item{df.name}{Name of the input DataFrame.} - -\item{datasources}{Data sources from which to aggregate data.} -} -\value{ -A DataFrame containing the variable classes from each data source. -} -\description{ -Retrieves the class of each variable in the specified DataFrame from different data sources. -} diff --git a/man/dot-identify_class_conflicts.Rd b/man/dot-identify_class_conflicts.Rd deleted file mode 100644 index 439838f..0000000 --- a/man/dot-identify_class_conflicts.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.identify_class_conflicts} -\alias{.identify_class_conflicts} -\title{Identify Class Conflicts} -\usage{ -.identify_class_conflicts(classes) -} -\arguments{ -\item{classes}{A DataFrame containing variable classes across data sources.} -} -\value{ -A list of variables that have class conflicts. -} -\description{ -Identifies conflicts in variable classes across different data sources. -} diff --git a/man/dot-identify_factor_vars.Rd b/man/dot-identify_factor_vars.Rd deleted file mode 100644 index 1c0f41c..0000000 --- a/man/dot-identify_factor_vars.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.identify_factor_vars} -\alias{.identify_factor_vars} -\title{Identify Factor Variables} -\usage{ -.identify_factor_vars(var_classes) -} -\arguments{ -\item{var_classes}{A DataFrame containing variable classes.} -} -\value{ -A vector of factor variables. -} -\description{ -Identifies which variables are factors in the DataFrame. -} diff --git a/man/dot-identify_level_conflicts.Rd b/man/dot-identify_level_conflicts.Rd deleted file mode 100644 index 4edc810..0000000 --- a/man/dot-identify_level_conflicts.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.identify_level_conflicts} -\alias{.identify_level_conflicts} -\title{Identify Factor Level Conflicts} -\usage{ -.identify_level_conflicts(factor_levels) -} -\arguments{ -\item{factor_levels}{A list of factor levels.} -} -\value{ -A list of variables with level conflicts. -} -\description{ -Identifies conflicts in factor levels across different data sources. -} diff --git a/man/dot-make_levels_message.Rd b/man/dot-make_levels_message.Rd deleted file mode 100644 index ed9d3d0..0000000 --- a/man/dot-make_levels_message.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.make_levels_message} -\alias{.make_levels_message} -\title{Make Factor Level Conflict Message} -\usage{ -.make_levels_message(level_conflicts) -} -\arguments{ -\item{level_conflicts}{A list of variables with factor level conflicts.} -} -\value{ -None. Prints the message to the console. -} -\description{ -Creates a message to alert the user about factor level conflicts and prompt for action. -} diff --git a/man/dot-make_levels_recode_message.Rd b/man/dot-make_levels_recode_message.Rd deleted file mode 100644 index e25e970..0000000 --- a/man/dot-make_levels_recode_message.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.make_levels_recode_message} -\alias{.make_levels_recode_message} -\title{Make Levels Recode Message} -\usage{ -.make_levels_recode_message(unique_levels) -} -\arguments{ -\item{unique_levels}{A list of unique factor levels.} -} -\value{ -A formatted string summarizing the level recoding. -} -\description{ -Creates a message to alert the user about factor level recoding. -} diff --git a/man/dot-print_class_recode_message.Rd b/man/dot-print_class_recode_message.Rd deleted file mode 100644 index 94a0647..0000000 --- a/man/dot-print_class_recode_message.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.print_class_recode_message} -\alias{.print_class_recode_message} -\title{Print Class Recode Message} -\usage{ -.print_class_recode_message(class_decisions, different_classes, newobj) -} -\arguments{ -\item{class_decisions}{A vector of class decisions.} - -\item{different_classes}{A list of variables with class conflicts.} - -\item{newobj}{The name of the new DataFrame.} -} -\value{ -None. Prints the message to the console. -} -\description{ -Prints a message summarizing the class decisions that were made for variables with conflicts. -} diff --git a/man/dot-print_levels_recode_message.Rd b/man/dot-print_levels_recode_message.Rd deleted file mode 100644 index 2d1bff3..0000000 --- a/man/dot-print_levels_recode_message.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.print_levels_recode_message} -\alias{.print_levels_recode_message} -\title{Print Factor Levels Recode Message} -\usage{ -.print_levels_recode_message(unique_levels, newobj) -} -\arguments{ -\item{unique_levels}{A list of unique factor levels.} - -\item{newobj}{The name of the new DataFrame.} -} -\value{ -None. Prints the message to the console. -} -\description{ -Prints a message summarizing the factor level decisions that were made for variables with conflicts. -} diff --git a/man/dot-print_out_messages.Rd b/man/dot-print_out_messages.Rd deleted file mode 100644 index 6fcec42..0000000 --- a/man/dot-print_out_messages.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.print_out_messages} -\alias{.print_out_messages} -\title{Print Out Summary Messages} -\usage{ -.print_out_messages( - added_cols, - class_decisions, - different_classes, - unique_levels, - level_conflicts, - levels_decision, - newobj -) -} -\arguments{ -\item{added_cols}{A list of added columns.} - -\item{class_decisions}{A vector of class decisions.} - -\item{different_classes}{A list of variables with class conflicts.} - -\item{unique_levels}{A list of unique factor levels.} - -\item{level_conflicts}{A list of variables with level conflicts.} - -\item{levels_decision}{The decision made regarding factor levels.} - -\item{newobj}{The name of the new DataFrame.} -} -\value{ -None. Prints messages to the console. -} -\description{ -Prints summary messages regarding the filled DataFrame, including added columns, class decisions, and factor level adjustments. -} diff --git a/man/dot-print_var_recode_message.Rd b/man/dot-print_var_recode_message.Rd deleted file mode 100644 index ac5c93a..0000000 --- a/man/dot-print_var_recode_message.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.print_var_recode_message} -\alias{.print_var_recode_message} -\title{Print Variable Recode Message} -\usage{ -.print_var_recode_message(added_cols, newobj) -} -\arguments{ -\item{added_cols}{A list of added columns.} - -\item{newobj}{The name of the new DataFrame.} -} -\value{ -None. Prints the message to the console. -} -\description{ -Prints a message summarizing the columns that were added to the DataFrame. -} diff --git a/man/dot-set_factor_levels.Rd b/man/dot-set_factor_levels.Rd deleted file mode 100644 index 87d6c98..0000000 --- a/man/dot-set_factor_levels.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.set_factor_levels} -\alias{.set_factor_levels} -\title{Set Factor Levels in DataFrame} -\usage{ -.set_factor_levels(newobj, unique_levels, datasources) -} -\arguments{ -\item{newobj}{The name of the new DataFrame.} - -\item{unique_levels}{A list of unique factor levels.} - -\item{datasources}{Data sources from which to aggregate data.} -} -\value{ -None. Updates the DataFrame with the new factor levels. -} -\description{ -Applies the unique factor levels to the DataFrame. -} diff --git a/man/dot-stop_if_cols_identical.Rd b/man/dot-stop_if_cols_identical.Rd deleted file mode 100644 index d5b35c6..0000000 --- a/man/dot-stop_if_cols_identical.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.stop_if_cols_identical} -\alias{.stop_if_cols_identical} -\title{Stop If Columns Are Identical} -\usage{ -.stop_if_cols_identical(col_names) -} -\arguments{ -\item{col_names}{A list of column names from different data sources.} -} -\value{ -None. Throws an error if columns are identical. -} -\description{ -Checks if the columns in the data frames are identical and throws an error if they are. -} diff --git a/man/dot-summarise_new_cols.Rd b/man/dot-summarise_new_cols.Rd deleted file mode 100644 index 9f2f1d1..0000000 --- a/man/dot-summarise_new_cols.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{.summarise_new_cols} -\alias{.summarise_new_cols} -\title{Summarize Newly Added Columns} -\usage{ -.summarise_new_cols(newobj, datasources, col_names) -} -\arguments{ -\item{newobj}{The name of the new DataFrame.} - -\item{datasources}{Data sources from which to aggregate data.} - -\item{col_names}{A list of column names.} -} -\value{ -A list of added columns. -} -\description{ -Summarizes the columns that were added to the DataFrame. -} diff --git a/man/ds.tidy_fill.Rd b/man/ds.tidy_fill.Rd index 0b739be..947682d 100644 --- a/man/ds.tidy_fill.Rd +++ b/man/ds.tidy_fill.Rd @@ -20,6 +20,3 @@ The filled DataFrame with added columns and adjusted classes or factor levels. This function fills a given DataFrame by adding missing columns, ensuring consistent column classes, and adjusting factor levels where necessary. It performs checks to detect class and factor level conflicts and prompts the user for decisions to resolve these conflicts. } -\examples{ -ds.tidy_fill(df.name = "df1", newobj = "filled_df", datasources = conns) -} diff --git a/man/prompt_user_class_decision.Rd b/man/prompt_user_class_decision.Rd deleted file mode 100644 index 26583d3..0000000 --- a/man/prompt_user_class_decision.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{prompt_user_class_decision} -\alias{prompt_user_class_decision} -\title{Prompt User for Class Decision for a Single Variable} -\usage{ -prompt_user_class_decision(var, all_servers, all_classes) -} -\arguments{ -\item{var}{The variable name with a class conflict.} - -\item{all_servers}{The names of all servers.} - -\item{all_classes}{The classes of the variable across servers.} -} -\value{ -A decision for the variable's class. -} -\description{ -Prompts the user to resolve a class conflict for a single variable. -} diff --git a/man/prompt_user_class_decision_all_vars.Rd b/man/prompt_user_class_decision_all_vars.Rd deleted file mode 100644 index 7387ff3..0000000 --- a/man/prompt_user_class_decision_all_vars.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ds.tidy_fill.R -\name{prompt_user_class_decision_all_vars} -\alias{prompt_user_class_decision_all_vars} -\title{Prompt User for Class Decision for All Variables} -\usage{ -prompt_user_class_decision_all_vars(vars, all_servers, all_classes) -} -\arguments{ -\item{vars}{A vector of variable names with class conflicts.} - -\item{all_servers}{The names of all servers.} - -\item{all_classes}{The classes of the variables across servers.} -} -\value{ -A vector of decisions for each variable's class. -} -\description{ -Prompts the user to resolve class conflicts for all variables. -} diff --git a/tests/testthat/_snaps/tidy_fill.md b/tests/testthat/_snaps/tidy_fill.md new file mode 100644 index 0000000..204b85c --- /dev/null +++ b/tests/testthat/_snaps/tidy_fill.md @@ -0,0 +1,13 @@ +# ask_question displays the correct prompt + + Code + ask_question("my_var") + Message + i Would you like to: + 1. Convert `my_var` to a factor in all studies + 2. Convert `my_var` to an integer in all studies + 3. Convert `my_var` to numeric in all studies + 4. Convert `my_var` to a character in all studies + 5. Convert `my_var` to a logical vector in all studies + 6. Cancel `ds.dataFrameFill` operation + diff --git a/tests/testthat/test-tidy_fill.R b/tests/testthat/test-tidy_fill.R index 8b6829f..46c8d7f 100644 --- a/tests/testthat/test-tidy_fill.R +++ b/tests/testthat/test-tidy_fill.R @@ -125,7 +125,7 @@ test_that(".get_var_classes returns correct output", { }) -class_conflicts <- .identify_class_conflicts(var_classes) +class_conflicts <- .identify_class_conflicts(var_class) test_that(".identify_class_conflicts returns correct output", { expected <- list( @@ -141,14 +141,6 @@ test_that("ask_question displays the correct prompt", { expect_snapshot(ask_question("my_var")) }) -# Load the testthat package -library(testthat) - -# Define a mock version of the question function -mock_question <- function(var) { - return(paste("Prompting again for:", var)) -} - test_that("check_response_class aborts on input '6'", { expect_error(check_response_class("6", "variable_name"), "Aborted `ds.dataFrameFill`") })