library(magrittr)
dataValues <- data.frame(dataElement = rnorm(10),
value = 1:10)
dataValues %>%
tidyr::pivot_wider(., id_cols = dataElement, names_from = dataElement, values_from = value)
#> Error in `stop_subscript()`:
#> ! Can't subset columns that don't exist.
#> x Column `dataElement` doesn't exist.
reprex::reprex()
#> i Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector
library(magrittr)
dataValues <- data.frame(dataElement = rnorm(10),
value = 1:10)
dataValues %>%
tidyr::pivot_wider(., id_cols = "dataElement", names_from = "dataElement", values_from = "value")
#> Error in `stop_subscript()`:
#> ! Can't subset columns that don't exist.
#> x Column `dataElement` doesn't exist.
reprex::reprex()
#> i Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector
Check out the documentation for the id_cols argument in pivot_wider(), in particular its function and the default values.
A small thing, but the magrittr pipe assigns the LHS to the first argument of the RHS function or where the . placeholder appears. For pivot_wider() the first argument is data, so there is no need to include ., in the first position.