partial(mean, list(na.rm = T))

I want to get an equivalent to mean(..., na.rm = T) with partial means.
Here is my example

a <- list(na.rm = TRUE)
purrr::partial(mean, !!!a)(c(1, NA, 3))
#> Error in !a: invalid argument type
purrr::partial(mean, !!!a)
#> function (...) 
#> mean(!!!a, ...)

purrr::partial(...f = mean, ... = !!!a)(c(1, NA, 3))
#> [1] NA
purrr::partial(...f = mean, ... = !!!a)
#> function (...) 
#> mean(... = !!!a, ...)

Created on 2019-02-01 by the reprex package (v0.2.1)

Hi @gray, Is there something more to your question than just doing the following?

f <- purrr::partial(mean, na.rm = TRUE)
f
#> function (...) 
#> mean(na.rm = TRUE, ...)
f(c(1, NA, 3))
#> [1] 2

Created on 2019-02-01 by the reprex package (v0.2.1)

1 Like

yes, it is. The main problem is passing and unfolding a list named a

In fact, purrr::partial did not support splicing and quasiquotation... until 0.3.0 that came out a few days ago !!

It is just a new feature and now it works

library(purrr)
sessioninfo::package_info("purrr")
#>  package  * version date       lib source        
#>  magrittr   1.5     2014-11-22 [1] CRAN (R 3.5.1)
#>  purrr    * 0.3.0   2019-01-27 [1] CRAN (R 3.5.2)
#>  rlang      0.3.1   2019-01-08 [1] CRAN (R 3.5.2)
#> 
#> [1] C:/Users/chris/Documents/R/win-library/3.5
#> [2] C:/Program Files/R/R-3.5.1/library
a <- list(na.rm = TRUE)
mean2 <- partial(mean, !!!a)
mean2
#> <partialised>
#> function (...) 
#> mean(na.rm = TRUE, ...)
mean2(c(1, NA, 2))
#> [1] 1.5

See NEWS.

2 Likes

thank you very much!
By the way, do you know a handy tool to track all such NEWS.Rmd files for packages in tidyverse and tidymodels?

no I don't know such tool.

But I believe you could do something that is watching the NEWS file and report differences each day. Does not seems to hard to implement. You would only need to download the NEWS file (not cloning the all repos)

However, you can watch tidyverse website for release. There is usually a blog post.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.