Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to print errors and warnings #118

Closed
ddsjoberg opened this issue Jan 17, 2024 · 1 comment · Fixed by #120
Closed

Add function to print errors and warnings #118

ddsjoberg opened this issue Jan 17, 2024 · 1 comment · Fixed by #120
Assignees
Milestone

Comments

@ddsjoberg
Copy link
Collaborator

Perhaps something like this:

ard <- 
  mtcars |> 
  cards::ard_continuous(
    variables = c("mpg", "hp"),
    statistics = ~list(
      mean = \(x) mean(x),
      mean_warn = \(x) {warning("This is your warning!"); mean(x)},
      errr = \(x) stop("That's it! STOP!")
    )
  )
ard

print_messages <- function(x) {
  ard_warning <- x |> dplyr::filter(cards:::map_lgl(.data$warning, Negate(is.null)))
  ard_error <- x |> dplyr::filter(cards:::map_lgl(.data$error, Negate(is.null)))
  
  
  # this section needs to be updated to: 
  #  1. add the variable level if populated
  #  2. add the grouping variables/levels if populated
  cli::cli_bullets(c(
    "The following warnings were observed:",
    "!" = "Variable {.var {ard_warning$variable[[1]]}} for statistic {.val {ard_warning$stat_name[[1]]}}: {cli::col_yellow(ard_warning$warning[[1]])}",
    "!" = "Variable {.var {ard_warning$variable[[2]]}} for statistic {.val {ard_warning$stat_name[[2]]}}: {cli::col_yellow(ard_warning$warning[[2]])}"
  ))
  
  cli::cli_bullets(c(
    "The following errors occured:",
    "x" = "Variable {.var {ard_error$variable[[1]]}} for statistic {.val {ard_error$stat_name[[1]]}}: {cli::col_red(ard_error$error[[1]])}",
    "x" = "Variable {.var {ard_error$variable[[2]]}} for statistic {.val {ard_error$stat_name[[2]]}}: {cli::col_red(ard_error$error[[2]])}"
  ))
}

print_messages(ard)

image

For ARDs like ard_ttest() we can have one error for every statistic returned. In these cases, the messages should be grouped by the groups, variables, and error message. We can list all the statistics the error applies applies to.

@ddsjoberg ddsjoberg added this to the v0.1.0 milestone Jan 17, 2024
@ddsjoberg
Copy link
Collaborator Author

@bzkrouse what do you think of this format? should we change anything?

@ddsjoberg ddsjoberg self-assigned this Jan 18, 2024
ddsjoberg added a commit that referenced this issue Jan 26, 2024
**What changes are proposed in this pull request?**
Adds the `print_ard_conditions()` function

**Reference GitHub issue associated with pull request.** _e.g., 'closes
#1'_
closes #118 

<img width="850" alt="image"
src="https://github.com/insightsengineering/cards/assets/26774684/bb62e550-734f-45a3-b149-8488ef3e3816">



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

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

- [ ] Ensure all package dependencies are installed:
`devtools::install_dev_deps()`
- [ ] 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.
- [ ] Run `pkgdown::build_site()`. Check the R console for errors, and
review the rendered website.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`
- [ ] `usethis::use_spell_check()` runs with no spelling errors in
documentation

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cards (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).
- [ ] Increment the version number using `usethis::use_version(which =
"dev")`
- [ ] Run `usethis::use_spell_check()` again
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge".

---------

Signed-off-by: Daniel Sjoberg <danield.sjoberg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant