Skip to content

Commit

Permalink
fix #76 move transformation_tbl to internally exported pkg object
Browse files Browse the repository at this point in the history
  • Loading branch information
egouldo committed Aug 10, 2024
1 parent ccbcadb commit 0e58b86
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
34 changes: 11 additions & 23 deletions R/clean_response_transformation.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
#' Clean response transformation variable
#' @description Cleans the response transformation variable to the names of the back-transformation functions
#'
#' @param response_transformation A character vector with the
#' @param response_transformation A character vector with the response transformation values
#' @param transformation_tbl A tibble of the response transformation values `transformation_orig` and their cleaned names `cleaned_transformation`
#'
#'
#' @return A character vector of cleaned response transformation values equal to the required `transformation` values in `conversion()`
#' @export
#'
#' @details
#' The `transformation_tbl` is a tibble of the response transformation values `transformation_orig` and their cleaned
#' names `cleaned_transformation`. The `transformation_orig` values are the original response transformation values
#' used by the analyst. The `cleaned_transformation` values are the cleaned response transformation values that are equal to the required `transformation` values in [conversion()].
#' The user can supply an alternate table of transformations depending on what is required for the back-transformation functions.
#' @family back-transformation functions
clean_response_transformation <- function(response_transformation) {
clean_response_transformation <- function(response_transformation,
transformation_tbl = ManyEcoEvo:::transformation_tbl) {
original_data <- tibble(transformation_orig = response_transformation)

transformation_tbl <- tribble(
~transformation_orig, ~cleaned_transformation,
"^2", "square",
"power2", "square",
"^3", "cube",
"power3", "cube",
"squared", "square",
"cubed", "cube",
"scaled and centered", "identity",
"scaling and centering", "identity",
"mean centered and standardized", "identity",
"log", "log",
"orderNorm", NA, # TODO, ensure that this is the best behaviour - we need to exclude this first, rather than let it through here.. because else it gets passed through identity_back() inside conversion()
"divided.by.14", "divided.by.14",
"square.root", "square_root",
"back.transformed", "back.transformed",
"z.score", "identity",
"(power3)/100", "(power3)/100"
) # TODO double-check treatment of z.score

out <- original_data %>%
left_join(transformation_tbl) %>%
select(cleaned_transformation) %>% # TODO WHAT ABOUT MISSING NON-STANDARD TRANSFORMATIONS??
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
23 changes: 23 additions & 0 deletions data-raw/create_internal_pkg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,28 @@ prediction_ids <- tibble::tribble(
"Cessnock-1-1-1"
) # TODO ask HF where/how derived (used data pasta to copy from HF's files)

# ------ Create transformation_tbl -----

transformation_tbl <- tribble(
~transformation_orig, ~cleaned_transformation,
"^2", "square",
"power2", "square",
"^3", "cube",
"power3", "cube",
"squared", "square",
"cubed", "cube",
"scaled and centered", "identity",
"scaling and centering", "identity",
"mean centered and standardized", "identity",
"log", "log",
"orderNorm", NA, # TODO, ensure that this is the best behaviour - we need to exclude this first, rather than let it through here.. because else it gets passed through identity_back() inside conversion()
"divided.by.14", "divided.by.14",
"square.root", "square_root",
"back.transformed", "back.transformed",
"z.score", "identity",
"(power3)/100", "(power3)/100"
)


# ------- Write data internally -------

Expand All @@ -374,6 +396,7 @@ usethis::use_data(expert_subset,
collinearity_subset,
prediction_ids,
effect_ids,
transformation_tbl,
internal = TRUE,
overwrite = TRUE
)

0 comments on commit 0e58b86

Please sign in to comment.