Skip to contents

Extract a character column in an ir object into multiple columns using regular expression groups

Usage

extract.ir(
  data,
  col,
  into,
  regex = "([[:alnum:]]+)",
  remove = TRUE,
  convert = FALSE,
  ...
)

Arguments

data

An object of class ir.

col

Column name or position. This is passed to tidyselect::vars_pull().

This argument is passed by expression and supports quasiquotation (you can unquote column names or column positions).

into

Names of new variables to create as character vector. Use NA to omit the variable in the output.

regex

A string representing a regular expression used to extract the desired values. There should be one group (defined by ()) for each element of into.

remove

If TRUE, remove input column from output data frame.

convert

If TRUE, will run type.convert() with as.is = TRUE on new columns. This is useful if the component columns are integer, numeric or logical.

NB: this will cause string "NA"s to be converted to NAs.

...

Additional arguments passed on to methods.

Value

data with an extracted character column. See tidyr::extract().

Examples

## extract
ir_sample_data %>%
  tidyr::extract(
    id_sample,  "a"
  )
#> # A tibble: 58 × 7
#>    id_measurement a     sample_type sample_comment   klason_lignin holocellulose
#>             <int> <chr> <chr>       <chr>            <units>       <units>      
#>  1              1 GN    needles     Abies Firma Mom… 0.359944      0.3084       
#>  2              2 GN    needles     Cupressocyparis… 0.339405      0.2497       
#>  3              3 GN    needles     Juniperus chine… 0.267552      0.3362       
#>  4              4 GN    needles     Metasequoia gly… 0.350016      0.1844       
#>  5              5 GN    needles     Pinus strobus T… 0.331100      0.3092       
#>  6              6 GN    needles     Pseudolarix ama… 0.279360      0.3355       
#>  7              7 GN    needles     Sequoia semperv… 0.329672      0.2408       
#>  8              8 GN    needles     Taxodium distic… 0.356950      0.1253       
#>  9              9 GN    needles     Thuja occidenta… 0.369360      0.2517       
#> 10             10 GN    needles     Tsuga carolinia… 0.289050      0.3487       
#> # … with 48 more rows, and 1 more variable: spectra <named list>