Skip to content

build_longer_spec() should transform before casting #1233

@DavisVaughan

Description

@DavisVaughan

This would match the rectangling functions and I think it generally makes more sense, as you use the transform to do the hard work, then the cast to validate your assumptions.

tidyr/R/pivot-long.R

Lines 317 to 328 in a63a537

# optionally, cast variables generated from columns
cast_cols <- intersect(names(names), names(names_ptypes))
for (col in cast_cols) {
names[[col]] <- vec_cast(names[[col]], names_ptypes[[col]])
}
# transform cols
coerce_cols <- intersect(names(names), names(names_transform))
for (col in coerce_cols) {
f <- as_function(names_transform[[col]])
names[[col]] <- f(names[[col]])
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementpivoting ♻️pivot rectangular data to different "shapes"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions