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

Conversation

Projects
None yet
2 participants
@krlmlr
Copy link
Member

krlmlr commented Nov 1, 2016

to change factor labels programmatically.

@hadley: PTAL.

@hadley
Copy link
Member

hadley left a comment

Looks good. Just a few minor changes.

R/relabel.R Outdated

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

This comment has been minimized.

@hadley

hadley Dec 30, 2016

Member

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.

R/relabel.R Outdated
#' fct_count(rincome2)
fct_relabel <- function(f, fun, ...) {
if (!is.function(fun)) {
stop("expected function, got ", class(fun), call. = FALSE)

This comment has been minimized.

@hadley

hadley Dec 30, 2016

Member

Can you please start error messages with a capital letter?

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

R/relabel.R Outdated
#'
#' convert_income(levels(gss_cat$rincome))
#'
#' rincome2 <- fct_relabel(gss_cat$rincome,

This comment has been minimized.

@hadley

hadley Dec 30, 2016

Member

Should be one line

@krlmlr krlmlr force-pushed the krlmlr:f-relabel branch from c5c6ce4 to 25e6cfa Dec 30, 2016

@krlmlr

This comment has been minimized.

Copy link
Member

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

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hadley

This comment has been minimized.

Copy link
Member

hadley commented Dec 30, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment