Skip to content

Use vec_interleave() in pivot_longer() #1310

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

Closed
DavisVaughan opened this issue Jan 31, 2022 · 0 comments · Fixed by #1341
Closed

Use vec_interleave() in pivot_longer() #1310

DavisVaughan opened this issue Jan 31, 2022 · 0 comments · Fixed by #1341
Labels
feature a feature request or enhancement performance 🏎️ pivoting ♻️ pivot rectangular data to different "shapes" vctrs ↗️

Comments

@DavisVaughan
Copy link
Member

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

@DavisVaughan DavisVaughan added feature a feature request or enhancement pivoting ♻️ pivot rectangular data to different "shapes" vctrs ↗️ performance 🏎️ labels Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement performance 🏎️ pivoting ♻️ pivot rectangular data to different "shapes" vctrs ↗️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant