mikemc / speedyseq

Speedy versions of phyloseq functions
https://mikemc.github.io/speedyseq/
Other
46 stars 6 forks source link

add `transform_sample_data(physeq)` function to facilitate modifying sample data in pipes #33

Closed mikemc closed 3 years ago

mikemc commented 4 years ago

Example use:

physeq <- physeq %>%
  transform_sample_data(new_var1 = f(old_var), new_var2 = vec_of_length_nsamples) %>%
  transform_sample_counts(function(x) x / sum(x))

All the function will do is pass ... to base::transform(sample_data(physeq), ...) and update the sample_data with the results.

mikemc commented 4 years ago

Could also be nice to have a mutate_sample_data() function that allows using dplyr::mutate() as the backend. Implementation should be straightforward once the new as_tibble() methods are implemented,

function(ps, ...) {
  sample_data(ps) %>%
    as_tibble %>%
    mutate(...) %>%
    sample_data
}
mikemc commented 3 years ago

The ps_mutate() function in the new microViz package provides this behavior

mikemc commented 3 years ago

Also, we have mutate_sample_data() as of 7a77af1 to give dplyr mutate functionality in speedyseq, and I don't see a need for a base-R version