Closed ajacoby closed 2 years ago
Yes, you are right. An update to tidyr broke the old code, and the new code should be:
example_eagle_nests %>%
pivot_longer(
cols = c(`2007`, `2009`),
names_to = "year",
names_transform = list(year = as.integer),
values_to = "num_nests"
)
We will be updating all of our books in upcoming weeks to the most recent versions of the Tidyverse packages, and we will include these changes.
Thanks for pointing this out!
Fixed. Thanks!
https://dcl-wrangle.stanford.edu/pivot_advanced.html has the example:
However, when I run this example I get the error:
Error: Can't convert <character> to <integer>.
Searching on this error leads to the page https://www.reddit.com/r/Rlanguage/comments/gu4ygj/tidyverse_nams_ptypes_argument_in_the_pivot/ which suggests the solution of using the
names_transform
argument instead. This worked for me, replacingnames_ptypes = list(year = integer())
withnames_transform = list(year = as.integer)
.I'm new to R and wondering if it has to do with the version of R that I'm using or what. I looked in the Welcome and Basics and didn't see a specification of which version of R (or tidyr) the text applies to. Perhaps the library has been updated since the text was written? I believe I'm using version 1.1.2 of tidyr and R 4.0.3.
Thanks for sharing your excellent materials freely online!