Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: accumulate2 returns a list, not a vector #774

Closed
jonathan-g opened this issue Jul 10, 2020 · 1 comment · Fixed by #909
Closed

Bug: accumulate2 returns a list, not a vector #774

jonathan-g opened this issue Jul 10, 2020 · 1 comment · Fixed by #909
Labels
bug an unexpected problem or unintended behavior reduce 🔨

Comments

@jonathan-g
Copy link

jonathan-g commented Jul 10, 2020

The documentation for accumulate and accumulate2 says that both functions return vectors ("A vector the same length of .x with the same names as .x"). In fact, accumulate returns a vector, but accumulate2 returns a list.

Expected behavior

accumulate2 returns a vector

Observed behavior

accumulate2 returns a list

Reprex

library(purrr)

f <- function(x, y, z) {
  x + y + z
}

accumulate(seq(5), f, 1)
#> [1]  1  4  8 13 19

accumulate2(seq(5), seq(4), f)
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 4
#> 
#> [[3]]
#> [1] 9
#> 
#> [[4]]
#> [1] 16
#> 
#> [[5]]
#> [1] 25

Created on 2020-07-10 by the reprex package (v0.3.0)

Session Info

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] reprex_0.3.0

loaded via a namespace (and not attached):
 [1] ps_1.3.3               digest_0.6.25          packrat_0.5.0          crayon_1.3.4           R6_2.4.1               lifecycle_0.2.0       
 [7] magrittr_1.5           evaluate_0.14          pillar_1.4.4           rlang_0.4.6            rstudioapi_0.11.0-9000 fs_1.4.2              
[13] callr_3.4.3            whisker_0.4            vctrs_0.3.1            ellipsis_0.3.1         rmarkdown_2.3.2.9002   tools_4.0.2           
[19] purrr_0.3.4            processx_3.4.3         xfun_0.15              compiler_4.0.2         pkgconfig_2.0.3        clipr_0.7.0           
[25] htmltools_0.5.0        knitr_1.29             tibble_3.0.2          
@lionel-
Copy link
Member

lionel- commented Jul 31, 2020

It's actually the intended behaviour because accumulate() should have returned a list all along. But since we're unlikely to ever make such a breaking change, it's probably better to make accumulate2() consistent with accumulate() instead.

lionel- added a commit to lionel-/lowliner that referenced this issue Aug 5, 2020
@lionel- lionel- added the bug an unexpected problem or unintended behavior label Aug 5, 2020
@hadley hadley closed this as completed in 1276623 Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior reduce 🔨
Projects
None yet
3 participants