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

.else not evaluated when passed to modify_if #701

Closed
hendrikvanb opened this issue Aug 29, 2019 · 2 comments · Fixed by #916
Closed

.else not evaluated when passed to modify_if #701

hendrikvanb opened this issue Aug 29, 2019 · 2 comments · Fixed by #916
Labels
bug an unexpected problem or unintended behavior modify 🛠️

Comments

@hendrikvanb
Copy link

It would appear that .else is not evaluated when passed to modify_if(). Unless I've missed something, I can only assume that this is a bug?

library(magrittr)

# with map_if, .else condition works as expected
purrr::map_if(1:10, ~(. < 5), ~(. = 1L), .else = ~(. = 10L)) %>% purrr::as_vector()
#>  [1]  1  1  1  1 10 10 10 10 10 10

# with modify_if, .else condition does not appear to be evaluated
purrr::modify_if(1:10, ~(. < 5), ~(. = 1L), .else = ~(. = 10L))
#>  [1]  1  1  1  1  5  6  7  8  9 10

sessionInfo()
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#> 
#> locale:
#>  [1] LC_CTYPE=en_ZA.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_ZA.UTF-8        LC_COLLATE=en_ZA.UTF-8    
#>  [5] LC_MONETARY=en_ZA.UTF-8    LC_MESSAGES=en_ZA.UTF-8   
#>  [7] LC_PAPER=en_ZA.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_ZA.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] magrittr_1.5
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_3.6.1   tools_3.6.1      htmltools_0.3.6  yaml_2.2.0      
#>  [5] Rcpp_1.0.2       stringi_1.4.3    rmarkdown_1.15   highr_0.8       
#>  [9] knitr_1.24       stringr_1.4.0    xfun_0.9         digest_0.6.20   
#> [13] rlang_0.4.0      evaluate_0.14    purrr_0.3.2.9000

Created on 2019-08-29 by the reprex package (v0.3.0)

@lionel- lionel- added bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day labels Jan 20, 2020
@lionel-

This comment has been minimized.

@lionel-
Copy link
Member

lionel- commented Jan 20, 2020

oops I now see you've already sent a PR.

@lionel- lionel- removed the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jan 20, 2020
hadley added a commit that referenced this issue Sep 6, 2022
Fixes #701. Originally implemented by @mgrlich in #724.
hadley added a commit that referenced this issue Sep 7, 2022
Fixes #701. Originally implemented by @mgrlich in #724.
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 modify 🛠️
Projects
None yet
3 participants