Skip to content

Instantly share code, notes, and snippets.

@infotroph
Created December 11, 2019 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infotroph/8f6f294d5047dabe0d524724c64b2604 to your computer and use it in GitHub Desktop.
Save infotroph/8f6f294d5047dabe0d524724c64b2604 to your computer and use it in GitHub Desktop.
> tribble(~"X0.0 cm", ~"X1.5 cm", 1, 2) %>%
+ pivot_longer(
+ cols = everything(),
+ names_pattern = "X([\\d.]+) cm",
+ names_ptypes = list(name=double()))
Error: Lossy cast from `x` <character> to `to` <double>.
Locations: 1
Run `rlang::last_error()` to see where the error occurred.
@infotroph
Copy link
Author

From ?pivot_longer

names_ptypes, values_ptypes: A list of of column name-prototype pairs. A prototype (or ptype for short) is a zero-length vector (like integer() or numeric()) that defines the type, class, and attributes of a vector.

If vctrs is going to complain about any char-to-double conversion, I don't see how numeric can work as documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment