How to install pivot_long() and pivot_wide() in R
Asked Answered
P

4

5

If you want to try these new functions (pivot_wide and pivot long), you need to install the development version of tidyr:

devtools::install_github("tidyverse/tidyr").

But I have not managed to achieved it. I install a list of libraries except one, ( vctrs) and I don't know if that's the problem.

When I run the next code:

  mtcars_wide1 <- mtcars %>%
  pivot_wide(names_from = "am",
             values_from = "mpg")

R couldn't find the function.

enter image description here

Can you recommend me something?

Pharmacist answered 10/6, 2019 at 21:54 Comment(0)
P
1

You probably don't have the lasted version of R installed - the latest is currently 3.6.1.

R.version

I had the same problem as you, but I updated R, reinstalled the dev version of the tidyverse

install.packages("devtools")
devtools::install_github("hadley/tidyverse")

…and all was good. Hope it works for you too!

Possibly answered 12/7, 2019 at 20:6 Comment(0)
L
2

It seems they changed their names to pivot_wider and pivot_longer:

https://github.com/tidyverse/tidyr/issues/579

Lacilacie answered 6/10, 2019 at 2:28 Comment(0)
G
2

pivot_longer() is from the package tidyr, so make sure it's installed and loaded:

install.packages("tidyr")
library(tidyr)
Gulledge answered 29/4, 2020 at 1:29 Comment(0)
P
1

You probably don't have the lasted version of R installed - the latest is currently 3.6.1.

R.version

I had the same problem as you, but I updated R, reinstalled the dev version of the tidyverse

install.packages("devtools")
devtools::install_github("hadley/tidyverse")

…and all was good. Hope it works for you too!

Possibly answered 12/7, 2019 at 20:6 Comment(0)
O
1

First, they changed the names to pivot_wider() and pivot_longer(). You need to change the function names in your code to these.

Second, these are now integrated into CRAN for tidyverse and you don't need the development version. If your R is already an updated version all you need to do is update the version of tidyverse by reinstalling it. Just run the code:

install.packages('tidyverse')

Or if you want to update all of your packages in R you can simply run:

update.packages()

This will take care of updating tidyverse and is in fact what I used and what worked for me after changing my code to pivot_wider().

Outthink answered 8/1, 2022 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.