Skip to content

Commit

Permalink
Adding variable/group columns to ard_stats_oneway_test() results (#141
Browse files Browse the repository at this point in the history
)

**What changes are proposed in this pull request?**
* Style this entry in a way that can be copied directly into `NEWS.md`.
(#<issue number>, @<username>)

Provide more detail here as needed.

**Reference GitHub issue associated with pull request.** _e.g., 'closes
#<issue number>'_



--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [ ] If a bug was fixed, a unit test was added.
- [ ] If a new `ard_*()` function was added, it passes the ARD
structural checks from `cards::check_ard_structure()`.
- [ ] If a new `ard_*()` function was added, `set_cli_abort_call()` has
been set.
- [ ] If a new `ard_*()` function was added and it depends on another
package (such as, `broom`), `is_pkg_installed("broom", reference_pkg =
"cardx")` has been set in the function call and the following added to
the roxygen comments: `@examplesIf
do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"",
reference_pkg = "cardx"))`
- [ ] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cardx (development version)`". If there is an issue
associated with the pull request, reference it in parentheses at the end
update (see `NEWS.md` for examples).
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
  • Loading branch information
ddsjoberg authored May 1, 2024
1 parent ee9e18e commit e867176
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions R/ard_stats_oneway_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ ard_stats_oneway_test <- function(formula, data, ...) {
check_class(formula, cls = "formula")

# build ARD ------------------------------------------------------------------

cards::tidy_as_ard(
lst_tidy =
cards::eval_capture_conditions(
stats::oneway.test(formula, data = data, ...) |>
broom::tidy()
),
tidy_result_names = c("num.df", "den.df", "statistic", "p.value", "method"),
fun_args_to_record =
c("var.equal"),
formals = formals(stats::oneway.test),
passed_args = dots_list(...),
lst_ard_columns = list(context = "stats_oneway_test")
) |>
df_results <-
cards::tidy_as_ard(
lst_tidy =
cards::eval_capture_conditions(
stats::oneway.test(formula, data = data, ...) |>
broom::tidy()
),
tidy_result_names = c("num.df", "den.df", "statistic", "p.value", "method"),
fun_args_to_record =
c("var.equal"),
formals = formals(stats::oneway.test),
passed_args = dots_list(...),
lst_ard_columns = list(context = "stats_oneway_test")
) |>
dplyr::mutate(
.after = "stat_name",
stat_label =
Expand All @@ -51,4 +51,12 @@ ard_stats_oneway_test <- function(formula, data, ...) {
TRUE ~ .data$stat_name,
)
)

# add variable/groups to results and return result
df_results |>
dplyr::bind_cols(
dplyr::tibble(!!!map(as.list(attr(stats::terms(formula), "variables"))[-1], as_label)) %>%
set_names(., c("variable", paste0("group", seq_len(length(.) - 1L))))
) |>
cards::tidy_ard_column_order()
}

0 comments on commit e867176

Please sign in to comment.