From 71e41c0e93e42d512097762d6f7b17eb8a7e55d3 Mon Sep 17 00:00:00 2001 From: "Steven Paul Sanderson II, MPH" Date: Thu, 7 Jul 2022 13:35:50 -0400 Subject: [PATCH] Fixes #216 --- NEWS.md | 2 ++ R/combine-multi-single-dist-tbl.R | 11 +++++++---- R/tidy-random-walk.R | 19 ++++++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index d314177b..107e6ee6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,8 @@ the display of the order of the parameters. to prevent the issue occurring in #212 4. Fix #212 - Make `tidy_distribution_comparison()` more robust in terms of handling bad or erroneous data. +5. Fix #216 - Add an attribute of "tibble_type" to `tidy_multi_single_dist()` which +helps it to work with other functions like `tidy_random_walk()` # TidyDensity 1.2.0 diff --git a/R/combine-multi-single-dist-tbl.R b/R/combine-multi-single-dist-tbl.R index 8aaf05c6..3d8de5f4 100644 --- a/R/combine-multi-single-dist-tbl.R +++ b/R/combine-multi-single-dist-tbl.R @@ -44,19 +44,21 @@ tidy_multi_single_dist <- function( # Check param ---- if (is.null(.tidy_dist)) { rlang::abort( - "Please enter a 'tidy_' distribution function like 'tidy_normal' - in quotes." + message = "Please enter a 'tidy_' distribution function like 'tidy_normal' + in quotes.", + use_cli_format = TRUE ) } if (length(.param_list) == 0) { rlang::abort( - "Please enter some parameters for your chosen 'tidy_' distribution." + message = "Please enter some parameters for your chosen 'tidy_' distribution.", + use_cli_format = TRUE ) } # Call used --- - td <- as.character(.tidy_dist) + td <- tolower(as.character(.tidy_dist)) # Params ---- params <- .param_list @@ -108,6 +110,7 @@ tidy_multi_single_dist <- function( # Attach attributes ---- attr(df_unnested_tbl, "all") <- atb + attr(df_unnested_tbl, "tibble_type") <- atb$tibble_type attr(df_unnested_tbl, "tbl") <- "tidy_multi_tibble" attr(df_unnested_tbl, ".num_sims") <- max(param_grid$.num_sims) attr(df_unnested_tbl, ".param_list") <- .param_list diff --git a/R/tidy-random-walk.R b/R/tidy-random-walk.R index e69badda..ddae99fc 100644 --- a/R/tidy-random-walk.R +++ b/R/tidy-random-walk.R @@ -56,17 +56,26 @@ tidy_random_walk <- function(.data, .initial_value = 0, .sample = FALSE, # Checks ---- if (!"tibble_type" %in% names(atb)) { - rlang::abort("Function expects to take in data from a 'tidy_' distribution - function.") + rlang::abort( + message = "Function expects to take in data from a 'tidy_' distribution + function.", + use_cli_format = TRUE + ) } if (initial_value < 0) { - rlang::abort("The .intial_value must be greater than or equal to zero.") + rlang::abort( + message = "The .intial_value must be greater than or equal to zero.", + use_cli_format = TRUE + ) } if (!value_type %in% c("cum_prod", "cum_sum")) { - rlang::abort("You chose an unsupported .value_type. Please chose from: - 'cum_prod', 'cum_sum'.") + rlang::abort( + message = "You chose an unsupported .value_type. Please chose from: + 'cum_prod', 'cum_sum'.", + use_cli_format = TRUE + ) } # Data ----