Skip to content

pivot_wider(values_fill requires is_scalar(), which is not nescesaily accessible by default #1604

@KasperThystrup

Description

@KasperThystrup

The issue

Transforming a data from long to wide and replacing NA with e.g. 0 (or "0") using pivot_wider() yields the following err:

Error in is_scalar(values_fill) : could not find function "is_scalar"

I'm uncertain which R package to use for providing is_scalar, it doesn't seem to be an integrated part of the tidyr exports.

Reprex

a <- dplyr::tibble(year = 2015:2020, feat = c("Good year", "Wierd year", "Funny year", "What happens in LA...", "Crappy year", "We're doomed!"), count = sample(x = 1:10, size = 6, replace = T))

tidyr::pivot_wider(a, names_from = year, values_from = count, values_fill = 0)

Traceback

3 pivot_wider_spec(data = data, spec = spec, id_cols = !!id_cols, id_expand = id_expand, names_repair = names_repair, values_fill = values_fill, values_fn = values_fn, unused_fn = unused_fn, error_call = current_env())
2 pivot_wider.data.frame(a, names_from = year, values_from = count, values_fill = 0)
1 tidyr::pivot_wider(a, names_from = year, values_from = count, values_fill = 0)

Info

sessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_Denmark.utf8 LC_CTYPE=English_Denmark.utf8
[3] LC_MONETARY=English_Denmark.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Denmark.utf8

time zone: Europe/Copenhagen
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] gtable_0.3.5 xfun_0.40 ggplot2_3.5.0 remotes_2.4.2.1
[5] htmlwidgets_1.6.4 devtools_2.4.5 tzdb_0.4.0 vctrs_0.6.3
[9] tools_4.3.1 generics_0.1.3 parallel_4.3.1 tibble_3.2.1
[13] fansi_1.0.4 pkgconfig_2.0.3 RColorBrewer_1.1-3 readxl_1.4.3
[17] lifecycle_1.0.4 compiler_4.3.1 farver_2.1.2 stringr_1.5.1
[21] textshaping_0.3.6 munsell_0.5.1 argparser_0.7.2 janitor_2.2.0
[25] snakecase_0.11.1 httpuv_1.6.15 usethis_2.2.2 htmltools_0.5.8.1
[29] yaml_2.3.7 urlchecker_1.0.1 later_1.3.2 pillar_1.9.0
[33] crayon_1.5.3 tidyr_1.3.0 ellipsis_0.3.2 cachem_1.1.0
[37] sessioninfo_1.2.2 mime_0.12 commonmark_1.9.1 tidyselect_1.2.0
[41] digest_0.6.36 stringi_1.7.12 dplyr_1.1.3 purrr_1.0.2
[45] labeling_0.4.3 fastmap_1.2.0 grid_4.3.1 colorspace_2.1-0
[49] cli_3.6.1 logger_0.3.0 magrittr_2.0.3 pkgbuild_1.4.4
[53] utf8_1.2.3 readr_2.1.4 withr_3.0.0 promises_1.3.0
[57] scales_1.3.0 bit64_4.0.5 lubridate_1.9.3 timechange_0.2.0
[61] bit_4.0.5 ggtext_0.1.2 cellranger_1.1.0 ragg_1.3.2
[65] hms_1.1.3 memoise_2.0.1 shiny_1.7.5.1 miniUI_0.1.1.1
[69] markdown_1.13 profvis_0.3.8 rlang_1.1.1 gridtext_0.1.5
[73] Rcpp_1.0.11 xtable_1.8-4 glue_1.6.2 xml2_1.3.5
[77] pkgload_1.4.0 svglite_2.1.2 rstudioapi_0.15.0 vroom_1.6.3
[81] R6_2.5.1 systemfonts_1.0.4 fs_1.6.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions