1

I've been following along with the Tidyr official documentation, trying to freshen up on it because I haven't used it in awhile.

One of the examples involving the billboard dataset produces the following error:

library(tidyr)

billboard %>% 
  pivot_longer(
    cols = starts_with("wk"), 
    names_to = "week", 
    names_prefix = "wk",
    names_transform = list(week = as.integer),
    values_to = "rank",
    values_drop_na = TRUE,
  )

Error in pivot_longer(., cols = starts_with("wk"), names_to = "week", : unused argument (names_transform = list(week = as.integer))

I'm a bit confused as to what's going on because as I mentioned earlier, this is in the official tidyr package documentation.

  • run `install.packages("tidyverse")` to update the packages – Abdessabour Mtk Feb 25 '21 at 18:56
  • Looks like that argument was added as of tidyr 1.1.0 2020-05-20. https://tidyr.tidyverse.org/news/index.html#general-features – Jon Spring Feb 25 '21 at 19:10
  • I keep trying to update the package and it never seems to work. Even when I go to the update tab and click tidyverse/tidyr specifically. I'll restart it tand everything and it will still say I'm on the old version. –  Feb 25 '21 at 20:45
  • 1
    @gooponyagrinch What is your `R version`? May be it is better to update R before doing any package updates. I am using R 4.0.4 – akrun Feb 25 '21 at 20:48
  • 1
    Yeah I updated my R version and now it works. Thanks! –  Feb 25 '21 at 20:55

1 Answers1

0

The current CRAN version for tidyr -1.1.2 returns the output without any errors

billboard %>% 
  pivot_longer(
     cols = starts_with("wk"), 
     names_to = "week", 
     names_prefix = "wk",
     names_transform = list(week = as.integer),
     values_to = "rank",
     values_drop_na = TRUE,
   )
# A tibble: 5,307 x 5
   artist  track                   date.entered  week  rank
   <chr>   <chr>                   <date>       <int> <dbl>
 1 2 Pac   Baby Don't Cry (Keep... 2000-02-26       1    87
 2 2 Pac   Baby Don't Cry (Keep... 2000-02-26       2    82
 3 2 Pac   Baby Don't Cry (Keep... 2000-02-26       3    72
 4 2 Pac   Baby Don't Cry (Keep... 2000-02-26       4    77
 5 2 Pac   Baby Don't Cry (Keep... 2000-02-26       5    87
 6 2 Pac   Baby Don't Cry (Keep... 2000-02-26       6    94
 7 2 Pac   Baby Don't Cry (Keep... 2000-02-26       7    99
 8 2Ge+her The Hardest Part Of ... 2000-09-02       1    91
 9 2Ge+her The Hardest Part Of ... 2000-09-02       2    87
10 2Ge+her The Hardest Part Of ... 2000-09-02       3    92
# … with 5,297 more rows
akrun
  • 874,273
  • 37
  • 540
  • 662