Subsets columns in a taxmap() object. Takes and returns a taxmap() object. Any variable name that appears in all_names() can be used as if it was a vector on its own. See dplyr::select() for the inspiration for this function and more information. Calling the function using the obj$select_obs(...) style edits "obj" in place, unlike most R functions. However, calling the function using the select_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$select_obs(data, ...)
select_obs(obj, data, ...)

Arguments

obj

An object of type taxmap()

data

Dataset names, indexes, or a logical vector that indicates which tables in obj$data to subset columns in. Multiple tables can be subset at once.

...

One or more column names to return in the new object. Each can be one of two things:

expression with unquoted column name

The name of a column in the dataset typed as if it was a variable on its own.

numeric

Indexes of columns in the dataset

To match column names with a character vector, use matches("my_col_name"). To match a logical vector, convert it to a column index using which.

target

DEPRECIATED. use "data" instead.

Value

An object of type taxmap()

See also

Examples

# Selecting a column by name select_obs(ex_taxmap, "info", dangerous)
#> <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 2 #> taxon_id dangerous #> <chr> <lgl> #> 1 m TRUE #> 2 n FALSE #> 3 o 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 #> 1 functions: #> reaction
# Selecting a column by index select_obs(ex_taxmap, "info", 3)
#> <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 2 #> taxon_id n_legs #> <chr> <dbl> #> 1 m 4 #> 2 n 4 #> 3 o 4 #> # … 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
# Selecting a column by regular expressions select_obs(ex_taxmap, "info", matches("^n"))
#> <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 3 #> taxon_id name n_legs #> <chr> <chr> <dbl> #> 1 m tiger 4 #> 2 n cat 4 #> 3 o mole 4 #> # … 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