Skip to content

format_<prediction type>() functions only format when necessary #922

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

Merged
merged 2 commits into from
Mar 14, 2023

Conversation

hfrick
Copy link
Member

@hfrick hfrick commented Mar 13, 2023

closes #263

The main part was done in #268 but since the issue was still open, this PR now extends it to newer prediction types.

@hfrick hfrick requested a review from EmilHvitfeldt March 13, 2023 14:37
Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the consistancy upgrade 🙌

Are these similar enough that we can have a helper function do it?

this_would_need_a_name <- function(x, col_name) {
  if (isTRUE(ncol(x) > 1) | is.data.frame(x)) {
    x <- as_tibble(x, .name_repair = "minimal")
    if (!any(grepl(paste0("^\\", col_name), names(x)))) {
      names(x) <- col_name
    }
  } else {
    x <- tibble(unname(x))
    names(x) <- col_name
    x
  }
}

@hfrick
Copy link
Member Author

hfrick commented Mar 13, 2023

Good thought - I'd say so, yes 🙌 I've introduced a helper here and added a follow-up issue #927. We might get to a general format_parsnip() helper but I didn't want to overload this PR.

@EmilHvitfeldt
Copy link
Member

Very nice! I think this is a good improvement

@hfrick hfrick merged commit 2bbb111 into main Mar 14, 2023
@hfrick hfrick deleted the formatting-functions branch March 14, 2023 09:43
@github-actions
Copy link

This pull request 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 Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

naming prediction columns
2 participants