-
Notifications
You must be signed in to change notification settings - Fork 417
Closed
Description
I love the new(ish) pivot_*()
functions. Although I use them a lot, I don't understand when to use ptypes
and when to use transform
. Could the documentation include examples for each? Data class mismatches are the most common error I face and I found suggestions to use each of these when looking on stackoverflow
library(tidyverse)
# no
mpg |> pivot_longer(cols = -year, values_ptypes = as.character())
mpg |> pivot_longer(cols = -year, values_ptypes = character())
mpg |> pivot_longer(cols = -year, values_ptypes = list(value = "character"))
# Error: Can't convert <double> to <character>.
# yes
mpg |> pivot_longer(cols = -year, values_transform = as.character)
# year name value
# <int> <chr> <chr>
# 1999 manufacturer audi
# 1999 model a4
# 1999 displ 1.8
# 1999 cyl 4
Metadata
Metadata
Assignees
Labels
No labels