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

loopify step_profile() #1177

Merged
merged 2 commits into from
Aug 1, 2023
Merged

loopify step_profile() #1177

merged 2 commits into from
Aug 1, 2023

Conversation

EmilHvitfeldt
Copy link
Member

Related to #1156.

This PR does a small refactor to step_profile() to bring them up to the same standard as #1156.

This step is quite different that most other steps as it doesn't use the new_data in bake(), so many of the check functions we normally use shouldn't be done here.


for (i in names(object$columns)) {
new_data[[i]] <- rep(object$columns[[i]], n)
new_data <- list()
Copy link
Member Author

Choose a reason for hiding this comment

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

I found it easier to create a empty list, fill it, order it, tibblify it. Than to modify the existing tibble, order it making sure the lengths matched

new_data[[names(object$profile)]] <- object$profile[[1]]

new_data <- vctrs::vec_recycle_common(!!!new_data)
Copy link
Member Author

@EmilHvitfeldt EmilHvitfeldt Jul 31, 2023

Choose a reason for hiding this comment

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

This function is so cool! We can avoid doing rep(value, n)

aaa <- list(1, 2, 4, 1:5)

vctrs::vec_recycle_common(!!!aaa)
#> [[1]]
#> [1] 1 1 1 1 1
#> 
#> [[2]]
#> [1] 2 2 2 2 2
#> 
#> [[3]]
#> [1] 4 4 4 4 4
#> 
#> [[4]]
#> [1] 1 2 3 4 5

Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

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

I dig it! One note on a pattern we may be able to use elsewhere in these PRs. :)

R/profile.R Outdated Show resolved Hide resolved
Co-authored-by: Simon P. Couch <[email protected]>
@EmilHvitfeldt EmilHvitfeldt merged commit f5f1aa7 into main Aug 1, 2023
9 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the loopify-profile branch August 1, 2023 21:10
@EmilHvitfeldt EmilHvitfeldt mentioned this pull request Aug 2, 2023
12 tasks
@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 Aug 16, 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.

2 participants