Add columns to tables in obj$data in taxmap() objects. See dplyr::mutate() for the inspiration for this function and more information. Calling the function using the obj$mutate_obs(...) style edits "obj" in place, unlike most R functions. However, calling the function using the mutate_obs(obj, ...) imitates R's traditional copy-on-modify semantics, so "obj" would not be changed; instead a changed version would be returned, like most R functions.

obj$mutate_obs(data, ...)
mutate_obs(obj, data, ...)

Arguments

obj

An object of type taxmap()

data

Dataset name, index, or a logical vector that indicates which dataset in obj$data to add columns to.

...

One or more named columns to add. Newly created columns can be referenced in the same function call. Any variable name that appears in all_names() can be used as if it was a vector on its own.

target

DEPRECIATED. use "data" instead.

Value

An object of type taxmap()

See also

Examples

# Add column to existing tables mutate_obs(ex_taxmap, "info", new_col = "Im new", newer_col = paste0(new_col, "er!"))
#> <Taxmap> #> 17 taxa: b. Mammalia, c. Plantae ... q. lycopersicum, r. tuberosum #> 17 edges: NA->b, NA->c, b->d, b->e ... j->o, k->p, l->q, l->r #> 4 data sets: #> info: #> # A tibble: 6 x 6 #> taxon_id name n_legs dangerous new_col newer_col #> <chr> <chr> <dbl> <lgl> <chr> <chr> #> 1 m tiger 4 TRUE Im new Im newer! #> 2 n cat 4 FALSE Im new Im newer! #> 3 o mole 4 FALSE Im new Im newer! #> # … with 3 more rows #> phylopic_ids: a named vector of 'character' with 6 items #> m. e148eabb-f138-43[truncated] ... r. 63604565-0406-46[truncated] #> foods: a list of 6 items named by taxa: #> m, n, o, p, q, r #> abund: #> # A tibble: 8 x 5 #> taxon_id code sample_id count taxon_index #> <chr> <fct> <fct> <dbl> <int> #> 1 m T A 1 1 #> 2 n C A 2 2 #> 3 o M B 5 3 #> # … with 5 more rows #> 1 functions: #> reaction
# Create columns in a new table mutate_obs(ex_taxmap, "new_table", nums = 1:10, squared = nums ^ 2)
#> Adding a new 10 x 2 table called "new_table"
#> <Taxmap> #> 17 taxa: b. Mammalia, c. Plantae ... q. lycopersicum, r. tuberosum #> 17 edges: NA->b, NA->c, b->d, b->e ... j->o, k->p, l->q, l->r #> 5 data sets: #> info: #> # A tibble: 6 x 4 #> taxon_id name n_legs dangerous #> <chr> <chr> <dbl> <lgl> #> 1 m tiger 4 TRUE #> 2 n cat 4 FALSE #> 3 o mole 4 FALSE #> # … with 3 more rows #> phylopic_ids: a named vector of 'character' with 6 items #> m. e148eabb-f138-43[truncated] ... r. 63604565-0406-46[truncated] #> foods: a list of 6 items named by taxa: #> m, n, o, p, q, r #> abund: #> # A tibble: 8 x 5 #> taxon_id code sample_id count taxon_index #> <chr> <fct> <fct> <dbl> <int> #> 1 m T A 1 1 #> 2 n C A 2 2 #> 3 o M B 5 3 #> # … with 5 more rows #> new_table: #> # A tibble: 10 x 2 #> nums squared #> <int> <dbl> #> 1 1 1 #> 2 2 4 #> 3 3 9 #> # … with 7 more rows #> 1 functions: #> reaction
# Add a new vector mutate_obs(ex_taxmap, "new_vector", 1:10)
#> Adding a new "integer" vector of length 10.
#> <Taxmap> #> 17 taxa: b. Mammalia, c. Plantae ... q. lycopersicum, r. tuberosum #> 17 edges: NA->b, NA->c, b->d, b->e ... j->o, k->p, l->q, l->r #> 5 data sets: #> info: #> # A tibble: 6 x 4 #> taxon_id name n_legs dangerous #> <chr> <chr> <dbl> <lgl> #> 1 m tiger 4 TRUE #> 2 n cat 4 FALSE #> 3 o mole 4 FALSE #> # … with 3 more rows #> phylopic_ids: a named vector of 'character' with 6 items #> m. e148eabb-f138-43[truncated] ... r. 63604565-0406-46[truncated] #> foods: a list of 6 items named by taxa: #> m, n, o, p, q, r #> abund: #> # A tibble: 8 x 5 #> taxon_id code sample_id count taxon_index #> <chr> <fct> <fct> <dbl> <int> #> 1 m T A 1 1 #> 2 n C A 2 2 #> 3 o M B 5 3 #> # … with 5 more rows #> new_vector: a vector of 'integer' with 10 items #> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 #> 1 functions: #> reaction
# Add a new list mutate_obs(ex_taxmap, "new_list", list(1, 2))
#> Adding a new "list" vector of length 2.
#> <Taxmap> #> 17 taxa: b. Mammalia, c. Plantae ... q. lycopersicum, r. tuberosum #> 17 edges: NA->b, NA->c, b->d, b->e ... j->o, k->p, l->q, l->r #> 5 data sets: #> info: #> # A tibble: 6 x 4 #> taxon_id name n_legs dangerous #> <chr> <chr> <dbl> <lgl> #> 1 m tiger 4 TRUE #> 2 n cat 4 FALSE #> 3 o mole 4 FALSE #> # … with 3 more rows #> phylopic_ids: a named vector of 'character' with 6 items #> m. e148eabb-f138-43[truncated] ... r. 63604565-0406-46[truncated] #> foods: a list of 6 items named by taxa: #> m, n, o, p, q, r #> abund: #> # A tibble: 8 x 5 #> taxon_id code sample_id count taxon_index #> <chr> <fct> <fct> <dbl> <int> #> 1 m T A 1 1 #> 2 n C A 2 2 #> 3 o M B 5 3 #> # … with 5 more rows #> new_list: a list of 2 items #> 1 functions: #> reaction