Skip to content

Commit

Permalink
- refactor!: rm unnecessary arguments to `back_transform_response_var…
Browse files Browse the repository at this point in the history
…s_yi()`, update call of function within `prepare_response_variables_yi()` #97

And update associated roxygen code, especially imports #102
  • Loading branch information
egouldo committed Sep 9, 2024
1 parent 19e94e7 commit bc8ae03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
9 changes: 2 additions & 7 deletions R/prepare_response_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,9 @@ prepare_response_variables <- function(data,
out <- out %>%
ungroup() %>%
dplyr::mutate(
data = purrr::map2( #TODO assign to data or not?
data = purrr::map(
.x = data,
.y = dataset,
.f = ~ back_transform_response_vars_yi(
dat = .x,
estimate_type = !!{estimate_type},
dataset = .y
)
.f = ~ back_transform_response_vars_yi(.x)
),
diversity_data =
map2(
Expand Down
35 changes: 12 additions & 23 deletions R/prepare_response_variables_yi.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@
#' `estimate_type` is used to specify the type of estimate to be standardised and parsed to [back_transform_response_vars_yi()]
#' @seealso [back_transform_response_vars_yi()]. To be called prior to [generate_yi_subsets()].
#' @import dplyr
#' @importFrom purrr map2
#' @importFrom purrr map2 map
#' @importFrom pointblank expect_col_exists
#' @family targets-pipeline functions
#' @family Multi-dataset Wrapper Functions
#' @export
prepare_response_variables_yi <- function(data,
estimate_type = character(1L),
param_table = NULL) {
prepare_response_variables_yi <- function(data) {
stopifnot(is.data.frame(data))
# TODO run checks on data
match.arg(estimate_type, choices = c("yi", "y25", "y50", "y75"), several.ok = FALSE)

pointblank::expect_col_exists(data, c("data", "diversity_data"))

out <- data %>%
ungroup() %>%
dplyr::mutate(
data = purrr::map2(
.x = data, .y = dataset,
.f = ~ back_transform_response_vars_yi(
dat = .x,
estimate_type = !!{
estimate_type
},
param_table,
dataset = .y
)
data = purrr::map(
.x = data,
.f = prepare_response_variables_yi
),
diversity_data = purrr::map2(
.x = diversity_data,
Expand All @@ -47,23 +39,20 @@ prepare_response_variables_yi <- function(data,
#' Back-transform analyst `yi` estiamtes to the response scale
#'
#' @param data dataframe of out of sample predictions analyst submission data
#' @param estimate_type The type of estimate to be standardised. Character vector of length 1, whose value may be "yi", "y25", "y50", "y75".
#' @param dataset One of either "blue tit" or "eucalyptus"
#'
#' @return A tibble of analyst data with standardised values contained in a list-column called 'back_transformed_data'
#' @details
#' `data` must contain the columns: `id_col`, `augmented_data`, `transformation`, `response_transformation_status`, where `augmented_data` is a list-column of dataframes containing the analyst predictions, `transformation` is the transformation used in the model, and `response_transformation_status` is the status of the response transformation.
#'
#' @export
#' @import dplyr
#' @importFrom purrr pmap
#' @importFrom rlang is_na na_lgl
#' @importFrom pointblank col_exists
#' @family Analysis-level functions
#' @family Back-transformation
back_transform_response_vars_yi <- function(data,
estimate_type = character(1L),
dataset = character(1L)) {
back_transform_response_vars_yi <- function(data) {
# TODO insert checks that appropriate columns exist
# TODO apply to data and check that all cases accounted for!
match.arg(estimate_type, choices = c("yi", "y25", "y50", "y75"), several.ok = FALSE)

out <- data %>%
pointblank::col_exists(
Expand Down

0 comments on commit bc8ae03

Please sign in to comment.