Open mikemc opened 5 years ago
For transform_sample_counts()
, a simple wrapper like
transform_sample_counts <- function(physeq, .f, ...){
fun <- purrr::as_mapper(.f)
phyloseq::transform_sample_counts(physeq, fun, ...)
}
works for single-argument functions, which might be all we really want, though should make sure the failure on multi-arg anonymous functions doesn't indicate any potential issues.
should make sure the failure on multi-arg anonymous functions doesn't indicate any potential issues.
It turns out phyloseq's transform_sample_counts currently doesn't work on multi-arg functions due to a missing ...
in the test call to fun
.
transform_sample_counts <- function(physeq, fun, ...){
# Test the user-provided function returns a vector of the same length as input.
if( !identical(length(fun(1:10)), 10L) ){stop("`fun` not valid function.")} # Should be fun(1:10, ...)
Idea is to be able to do
see https://purrr.tidyverse.org/articles/other-langs.html