Skip to content

Use vec_interleave() in pivot_longer() #1310

@DavisVaughan

Description

@DavisVaughan

Right here:

tidyr/R/pivot-long.R

Lines 259 to 265 in d46d22a

out <- vec_c(!!!val_cols, .ptype = val_type)
# Interleave into correct order
# TODO somehow `t(matrix(x))` is _faster_ than `matrix(x, byrow = TRUE)`
# if this gets fixed in R this should use `byrow = TRUE` again
n_vals <- nrow(data) * length(val_cols)
idx <- t(matrix(seq_len(n_vals), ncol = length(val_cols)))
vals[[value]] <- vec_slice(out, as.integer(idx))

As a follow up to #1132, which should make pivot_longer() a little faster, maybe do a benchmark against that PR.

Will require vctrs 0.3.9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions