taxa
taxa copied to clipboard
When adding new table with `mutate_obs` create `taxon_id` column if inputs named by taxon IDs
This will often happen when making new tables from the output of functions that return per-taxon values, such as obs_apply, supertaxa, subtaxa, subtaxa_apply, etc.
For example, instead of:
obj <- mutate_obs(obj,
"per_taxon",
taxon_id = taxon_ids,
mean_pid = unlist(obs_apply(obj, "query_data", mean, value = "pid")),
n_otus = unlist(obs_apply(obj, "query_data", value = "query", func = function(x) length(unique(x)))))
This would do the same:
obj <- mutate_obs(obj,
"per_taxon",
mean_pid = unlist(obs_apply(obj, "query_data", mean, value = "pid")),
n_otus = unlist(obs_apply(obj, "query_data", value = "query", func = function(x) length(unique(x)))))
since the output of unlist(obs_apply(....)) will be named by taxon IDs.
The taxon_id column would only be added if names of input vectors match and are all valid taxon IDs.