Skip to content

Commit

Permalink
#97 #102 replace first argument with data
Browse files Browse the repository at this point in the history
  • Loading branch information
egouldo committed Sep 6, 2024
1 parent d4e1c52 commit 29dd03b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions R/prepare_response_variables.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Prepare response variable data for nested ManyEcoEvo dataset
#'
#' @param ManyEcoEvo Complete ManyEcoEvo dataset containing nested datasets for each different analysis and exclusion set dataset
#' @param data Complete ManyEcoEvo dataset containing nested datasets for each different analysis and exclusion set dataset
#' @param estimate_type A character string of length 1, equal to either "Zr", "yi", "y25", "y50", "y75", indicating what type of estimates are being prepared.
#' @param param_table A table of parameters \(mean, sd\) for *most* response variables used by analysts. This tibble is pulled from the named object exported by `ManyEcoEvo::`. but can be overwritten with the users's own `param_table` dataset.
#' @param dataset_standardise A character string of length 1, equal to the name of the dataset to standardise the response variables to. If `NULL` (default), no datasets are standardised.
#' @param dataset_log_transform A character string of length 1, equal to the name of the dataset to log-transform the response variables to. If `NULL` (default), no datasets are log-transformed.
#' @return A tibble of nested list-columns
#' @details Operates on nested list-columns of dataframes, where each dataframe contains the response variable data for a single analysis. The function standardises the response variable data for each analysis, and returns the modified dataset to the `data` list-column.
#'
#' Note that if `ManyEcoEvo` does not have an `estimate_type` column, it will be added with the value of `estimate_type`. This is because some transformation functions require the `estimate_type` column to be present in the dataset.
#' Note that if `data` does not have an `estimate_type` column, it will be added with the value of `estimate_type`. This is because some transformation functions require the `estimate_type` column to be present in the dataset.
#'
#' @family targets-pipeline functions.
#' @family Multi-dataset Wrapper Functions
Expand All @@ -21,7 +21,7 @@
#' @importFrom tidyr tibble drop_na
#' @examples
#' ManyEcoEvo %>% prepare_response_variables(estimate_type = "Zr")
prepare_response_variables <- function(ManyEcoEvo,
prepare_response_variables <- function(data,
estimate_type = character(1L),
param_table = NULL,
dataset_standardise = NULL,
Expand All @@ -32,15 +32,15 @@ prepare_response_variables <- function(ManyEcoEvo,
choices = c("Zr", "yi", "y25", "y50", "y75"),
several.ok = FALSE)

stopifnot(is.data.frame(ManyEcoEvo))
stopifnot(is.data.frame(data))

pointblank::expect_col_exists(object = ManyEcoEvo,
columns = c(dataset, data))
pointblank::expect_col_exists(object = data,
columns = c("dataset", "data"))

if (!pointblank::test_col_exists(ManyEcoEvo, "estimate_type")) {
if (!pointblank::test_col_exists(data, "estimate_type")) {

ManyEcoEvo <- dplyr::mutate(ManyEcoEvo,
estimate_type = estimate_type)
data <- dplyr::mutate(data,
estimate_type = estimate_type)

}

Expand All @@ -49,11 +49,11 @@ prepare_response_variables <- function(ManyEcoEvo,
stopifnot(
is.character(dataset_standardise),
length(dataset_standardise) >= 1,
length(dataset_standardise) <= length(unique(ManyEcoEvo$dataset))
length(dataset_standardise) <= length(unique(data$dataset))
)

match.arg(dataset_standardise,
choices = ManyEcoEvo$dataset,
choices = data$dataset,
several.ok = TRUE)
}

Expand All @@ -62,11 +62,11 @@ prepare_response_variables <- function(ManyEcoEvo,
stopifnot(
is.character(dataset_log_transform),
length(dataset_log_transform) >= 1,
length(dataset_log_transform) <= length(unique(ManyEcoEvo$dataset))
length(dataset_log_transform) <= length(unique(data$dataset))
)

match.arg(dataset_log_transform,
choices = ManyEcoEvo$dataset,
choices = data$dataset,
several.ok = TRUE)
}

Expand Down Expand Up @@ -101,7 +101,7 @@ prepare_response_variables <- function(ManyEcoEvo,

# ------ Prepare Response Variables ------

out <- ManyEcoEvo
out <- data

if (estimate_type != "Zr") {

Expand Down

0 comments on commit 29dd03b

Please sign in to comment.