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

Suggested new convenience function: recast() #3785

Closed
foundinblank opened this issue Aug 29, 2018 · 4 comments
Closed

Suggested new convenience function: recast() #3785

foundinblank opened this issue Aug 29, 2018 · 4 comments

Comments

@foundinblank
Copy link

Tweeted about this earlier this week. Essentially, I do this a lot, and imagine many others do, too.

... %>% mutate(col1 = as.character(col1)) %>% ... 
... %>% mutate(col2 = as.integer(col2)) %>% ... 

It's clunky typing the column name twice, and while there's also mutate_at(vars(column_name), as.character), that also feels clunky too. I propose a convenience wrapper function, recast() such that:

... %>% recast(col1,col2, as.character) %>% ...
... %>% recast(col3,col4, as.numeric) %>% ...

(Thanks to JLS_Datascience for the idea.)

I'd like to try writing a function for this and then do a PR. I can model it off a similar convenience wrapper (which one?).

Can I?

@krlmlr
Copy link
Member

krlmlr commented Aug 29, 2018

Thanks. Have you seen mutate_at()?

@krlmlr
Copy link
Member

krlmlr commented Aug 29, 2018

I missed the part where you wrote about mutate_at() .

My gut feeling is that such a function should live elsewhere, partly because this functionality already can be achieved with existing tools. The vars() is a technical necessity for supporting more than one function, but doesn't add too much cognitive burden IMO.

#3433 is about providing a better interface for passing the functions.

@hadley
Copy link
Member

hadley commented Aug 29, 2018

And generally, I think you should solve type problems further up the pipeline (e.g. during import)

@hadley hadley closed this as completed Aug 29, 2018
@lock
Copy link

lock bot commented Feb 25, 2019

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

@lock lock bot locked and limited conversation to collaborators Feb 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants