pmap is not working for data frames
bnicenboim opened this issue · 1 comments
bnicenboim commented
I think the example is self-explanatory, purrr::pmap
does work while pmap
doesn't.
library(tidytable)
df <- tidytable(A= 1:10, b = 1:10)
pmap(df, function(A, ...) data.frame(A))
#> Error: i evaluates to a logical vector length 2 but there are 10 rows. Recycling of logical i is no longer allowed as it hides more bugs than is worth the rare convenience. Explicitly use rep(...,length=.N) if you really need to recycle.
purrr::pmap(df, function(A, ...) data.frame(A))
#> [[1]]
#> A
#> 1 1
#>
#> [[2]]
#> A
#> 1 2
#>
#> [[3]]
#> A
#> 1 3
#>
#> [[4]]
#> A
#> 1 4
#>
#> [[5]]
#> A
#> 1 5
#>
#> [[6]]
#> A
#> 1 6
#>
#> [[7]]
#> A
#> 1 7
#>
#> [[8]]
#> A
#> 1 8
#>
#> [[9]]
#> A
#> 1 9
#>
#> [[10]]
#> A
#> 1 10
sessionInfo()
#> R version 4.3.3 (2024-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.4 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=nl_NL.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=nl_NL.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=nl_NL.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Europe/Amsterdam
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] tidytable_0.11.1
#>
#> loaded via a namespace (and not attached):
#> [1] vctrs_0.6.5 cli_3.6.2 knitr_1.45 rlang_1.1.3
#> [5] xfun_0.42 purrr_1.0.2 styler_1.10.2 data.table_1.15.0
#> [9] glue_1.7.0 htmltools_0.5.7 fansi_1.0.6 rmarkdown_2.26
#> [13] R.cache_0.16.0 evaluate_0.23 fastmap_1.1.1 yaml_2.3.8
#> [17] lifecycle_1.0.4 compiler_4.3.3 fs_1.6.3 rstudioapi_0.15.0
#> [21] R.oo_1.25.0 R.utils_2.12.3 digest_0.6.34 utf8_1.2.4
#> [25] reprex_2.0.2 tidyselect_1.2.0 pillar_1.9.0 magrittr_2.0.3
#> [29] R.methodsS3_1.8.2 tools_4.3.3 withr_3.0.0
Created on 2024-03-08 with reprex v2.0.2
markfairbanks commented
All set! Thanks for catching this.
pacman::p_load(tidytable)
df <- tidytable(a = 1:3, b = 4:6)
pmap(df, ~ .x + .y)
#> [[1]]
#> [1] 5
#>
#> [[2]]
#> [1] 7
#>
#> [[3]]
#> [1] 9