gray
February 1, 2019, 4:25pm
1
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)
jrlewi
February 1, 2019, 9:25pm
2
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
gray
February 2, 2019, 12:24pm
3
yes, it is. The main problem is passing and unfolding a list named a
cderv
February 2, 2019, 1:09pm
4
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
gray
February 2, 2019, 2:08pm
5
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
?
cderv
February 2, 2019, 2:14pm
6
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.
system
Closed
February 9, 2019, 2:14pm
7
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.