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

New fct_relabel() #50

Merged
merged 15 commits into from Dec 30, 2016
Merged

New fct_relabel() #50

merged 15 commits into from Dec 30, 2016

Conversation

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Nov 1, 2016

to change factor labels programmatically.

@hadley: PTAL.

Copy link
Member

@hadley hadley left a comment

Looks good. Just a few minor changes.


old_levels <- levels(f)
new_levels <- fun(old_levels, ...)
if (!is.character(new_levels)) {
Copy link
Member

@hadley hadley Dec 30, 2016

I think it would be better to use lvls_revalue() here - the error messages won't be quite as good, but it keeps all the logic in one place.

#' fct_count(rincome2)
fct_relabel <- function(f, fun, ...) {
if (!is.function(fun)) {
stop("expected function, got ", class(fun), call. = FALSE)
Copy link
Member

@hadley hadley Dec 30, 2016

Can you please start error messages with a capital letter?

Also need to think about what happens when class has multiple values.

#'
#' convert_income(levels(gss_cat$rincome))
#'
#' rincome2 <- fct_relabel(gss_cat$rincome,
Copy link
Member

@hadley hadley Dec 30, 2016

Should be one line

@krlmlr
Copy link
Member Author

@krlmlr krlmlr commented Dec 30, 2016

Addressed all remarks and rebased, lvls_relabel() now shows a richer error message.

@hadley hadley merged commit 908e793 into tidyverse:master Dec 30, 2016
1 check passed
@hadley
Copy link
Member

@hadley hadley commented Dec 30, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants