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

un-muffle car anova #31

Open
cicdguy opened this issue Aug 5, 2021 · 0 comments
Open

un-muffle car anova #31

cicdguy opened this issue Aug 5, 2021 · 0 comments

Comments

@cicdguy
Copy link
Contributor

cicdguy commented Aug 5, 2021

Follow-up to #958 with idea from @collinf1 about how warnings can be handled instead of muffled.

NEST/teal.modules.clinical/issues/674) .

For the record, note that the message is caught and nothing indicates a message was generated. Alternatively, an adapted construction from below could be used to capture the message and eventually attached as an attribute to the result.

try_car_anova <- function(mod,
                          test.statistic) { # nolint

  y <- tryCatch(
    withCallingHandlers(
      expr = {
        warn_text <- c()
        list(
          aov = car::Anova(
            mod,
            test.statistic = test.statistic,
            type = "III"
          ),
          warn_text = warn_text
        )
      },
      warning = function(w) {
        # If a warning is detected it is handled as "w".
        warn_text <<- trimws(paste0("Warning in `try_car_anova`: ", w))

        # A warning is sometimes expected, then, we want to restart
        # the execution while ignoring the warning.
        invokeRestart("muffleWarning")
      }
    ),
    finally = {
    }
  )

  return(y)
}

Provenance:

Creator: anajens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant