Skip to content

Canonical approach to lookup-based replacement? #7694

@MichaelChirico

Description

@MichaelChirico

I am finding it a bit awkward to refactor code using plyr::mapvalues(), which looks like:

mapvalues(x, from_vector, to_vector)

Items in x found in from_vector are replaced by the corresponding entry in to_vector.

The closest analogue is case_match(), but using it often requires pretty substantial refactoring, e.g. if from_vector/to_vector come from arguments to a function. Elsewhere it is often convenient to keep from_vector/to_vector instead of writing them out manually in different arguments.

Another approach I've tried would basically be to do a join-and-replace lookup with a left_join() to tibble(from_vector, to_vector).

plyr::revalue() is similarly not trivial to migrate.

Am I missing something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions