Skip to contents

mutate() creates new fields in $metadata that are functions of existing metadata fields. It can also modify (if the name is the same as an existing field) and delete fields (by setting their value to NULL).

Usage

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

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

Arguments

.data

An rbiom object, such as from as_rbiom().

...

Passed on to dplyr::mutate() or dplyr::rename().

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

An rbiom object.

See also

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

Examples

    library(rbiom) 
    
    biom <- slice_max(hmp50, BMI, n = 6)
#> Warning:  Dropping 43 samples from biom object since they are not in the new metadata:
#>   "HMP01", "HMP02", "HMP03", "HMP04", "HMP05", "HMP06", "HMP07", "HMP08",
#>   "HMP10", "HMP11", "HMP12", "HMP13", "HMP14", "HMP15", "HMP16", "HMP17",
#>   "HMP18", "HMP19", …, "HMP49", and "HMP50".
    biom$metadata
#> # A tibble: 7 × 5
#>   .sample   Age   BMI `Body Site`    Sex   
#> * <chr>   <dbl> <dbl> <fct>          <fct> 
#> 1 HMP09      33    32 Saliva         Male  
#> 2 HMP25      33    32 Anterior nares Male  
#> 3 HMP37      38    31 Mid vagina     Female
#> 4 HMP27      24    30 Saliva         Female
#> 5 HMP43      24    30 Mid vagina     Female
#> 6 HMP36      24    29 Stool          Male  
#> 7 HMP48      24    29 Anterior nares Male  
    
    # Add a new field to the metadata
    biom <- mutate(biom, Obsese = BMI >= 30)
    biom$metadata
#> # A tibble: 7 × 6
#>   .sample   Age   BMI `Body Site`    Sex    Obsese
#> * <chr>   <dbl> <dbl> <fct>          <fct>  <lgl> 
#> 1 HMP09      33    32 Saliva         Male   TRUE  
#> 2 HMP25      33    32 Anterior nares Male   TRUE  
#> 3 HMP37      38    31 Mid vagina     Female TRUE  
#> 4 HMP27      24    30 Saliva         Female TRUE  
#> 5 HMP43      24    30 Mid vagina     Female TRUE  
#> 6 HMP36      24    29 Stool          Male   FALSE 
#> 7 HMP48      24    29 Anterior nares Male   FALSE 
    
    # Rename a metadata field
    biom <- rename(biom, 'Age (years)' = "Age")
    biom$metadata
#> # A tibble: 7 × 6
#>   .sample `Age (years)`   BMI `Body Site`    Sex    Obsese
#> * <chr>           <dbl> <dbl> <fct>          <fct>  <lgl> 
#> 1 HMP09              33    32 Saliva         Male   TRUE  
#> 2 HMP25              33    32 Anterior nares Male   TRUE  
#> 3 HMP37              38    31 Mid vagina     Female TRUE  
#> 4 HMP27              24    30 Saliva         Female TRUE  
#> 5 HMP43              24    30 Mid vagina     Female TRUE  
#> 6 HMP36              24    29 Stool          Male   FALSE 
#> 7 HMP48              24    29 Anterior nares Male   FALSE