Skip to contents

with() will return the result of your expression. within() will return an rbiom object.

Usage

# S3 method for class 'rbiom'
with(data, expr, ...)

# S3 method for class 'rbiom'
within(data, expr, clone = TRUE, ...)

Arguments

data

An rbiom object, such as from as_rbiom().

expr

Passed on to base::with() or base::within().

...

Not used.

clone

Create a copy of biom before modifying. If FALSE, biom is modified in place as a side-effect. See speed ups for use cases. Default: TRUE

Value

See description.

See also

Other transformations: modify_metadata, rarefy(), rarefy_cols(), slice_metadata, subset()

Examples

    library(rbiom) 
    
    with(hmp50, table(`Body Site`, Sex))
#>                 Sex
#> Body Site        Female Male
#>   Anterior nares      5    5
#>   Buccal mucosa       5    5
#>   Mid vagina         10    0
#>   Saliva              5    5
#>   Stool               5    5
    
    biom <- within(hmp50, {
      age_bin = cut(Age, 5)
      bmi_bin = cut(BMI, 5)
    })
    biom$metadata
#> # A tibble: 50 × 7
#>    .sample   Age   BMI `Body Site`    Sex    bmi_bin     age_bin    
#>  * <chr>   <dbl> <dbl> <fct>          <fct>  <fct>       <fct>      
#>  1 HMP01      22    20 Buccal mucosa  Female (19,21.6]   (21,24.8]  
#>  2 HMP02      24    23 Buccal mucosa  Male   (21.6,24.2] (21,24.8]  
#>  3 HMP03      28    26 Saliva         Male   (24.2,26.8] (24.8,28.6]
#>  4 HMP04      25    23 Saliva         Male   (21.6,24.2] (24.8,28.6]
#>  5 HMP05      27    24 Buccal mucosa  Female (21.6,24.2] (24.8,28.6]
#>  6 HMP06      32    25 Saliva         Male   (24.2,26.8] (28.6,32.4]
#>  7 HMP07      26    22 Buccal mucosa  Male   (21.6,24.2] (24.8,28.6]
#>  8 HMP08      27    26 Saliva         Female (24.2,26.8] (24.8,28.6]
#>  9 HMP09      33    32 Saliva         Male   (29.4,32]   (32.4,36.2]
#> 10 HMP10      22    20 Anterior nares Female (19,21.6]   (21,24.8]  
#> # ℹ 40 more rows