Skip to content

Commit

Permalink
Fixes #216
Browse files Browse the repository at this point in the history
  • Loading branch information
spsanderson committed Jul 7, 2022
1 parent dc72a1b commit 71e41c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions R/combine-multi-single-dist-tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions R/tidy-random-walk.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----
Expand Down

0 comments on commit 71e41c0

Please sign in to comment.