quoting the variables doesn't work:
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
Created on 2022-02-11 by the reprex package (v2.0.1)
But without specifying the id_cols it works!
library(magrittr)
dataValues <- data.frame(dataElement = rnorm(10),
value = 1:10)
dataValues %>%
tidyr::pivot_wider(., names_from = dataElement, values_from = value)
#> # A tibble: 1 x 10
#> `0.826986943418365` `-0.5214790113857` `-0.0650241880911871` `-0.84807319528~`
#> <int> <int> <int> <int>
#> 1 1 2 3 4
#> # ... with 6 more variables: `-0.224404300418023` <int>,
#> # `-1.31788368455247` <int>, `0.0915744709159496` <int>,
#> # `-1.33344284491811` <int>, `0.0647617762545832` <int>,
#> # `-0.22658374043902` <int>
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
Created on 2022-02-11 by the reprex package (v2.0.1)