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

Printing method for metrics #435

Closed
EmilHvitfeldt opened this issue May 15, 2023 · 2 comments · Fixed by #455
Closed

Printing method for metrics #435

EmilHvitfeldt opened this issue May 15, 2023 · 2 comments · Fixed by #455
Labels
feature a feature request or enhancement

Comments

@EmilHvitfeldt
Copy link
Member

  • I think a print method for the metric functions, if people are going to be creating them and dealing with them:
yardstick::sens
#> function (data, ...) 
#> {
#>     UseMethod("sens")
#> }
#> <bytecode: 0x117ee7e30>
#> <environment: namespace:yardstick>
#> attr(,"direction")
#> [1] "maximize"
#> attr(,"class")
#> [1] "class_metric" "metric"       "function"

## just an idea:
format.metric <- function(x, ...) {
    first_class <- class(x)[[1]]
    cli::cli_format_method({
        cli::cli_h3("A {.cls {first_class}} function to {attr(x, 'direction')} metrics")
    })
}

print.metric <- function(x, ...) {
    cat(format(x), sep = "\n")
    invisible(x)
}

yardstick::sens
#> 
#> ── A <class_metric> function to maximize metrics

Created on 2023-05-15 with reprex v2.0.2

Originally posted by @juliasilge in #434 (review)

@EmilHvitfeldt EmilHvitfeldt added the feature a feature request or enhancement label May 15, 2023
@simonpcouch
Copy link
Contributor

With an eye for #434, would also be awesome if it included something like:

if (!is.null(atrr(x, "by")) {
  cat(cli::cli_text("Internally grouped and summarized by {.field by}."))
}

Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants