[Superseded]

extract() has been superseded in favour of separate_wider_regex() because it has a more polished API and better handling of problems. Superseded functions will not go away, but will only receive critical bug fixes.

Given a regular expression with capturing groups, extract() turns each group into a new column. If the groups don't match, or the input is NA, the output will be NA.

# S3 method for class 'SummarizedExperiment'
extract(
  data,
  col,
  into,
  regex = "([[:alnum:]]+)",
  remove = TRUE,
  convert = FALSE,
  ...
)

Arguments

data

A data frame.

col

<tidy-select> Column to expand.

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

tidySummarizedExperiment

References

Hutchison, W.J., Keyes, T.J., The tidyomics Consortium. et al. The tidyomics ecosystem: enhancing omic data analyses. Nat Methods 21, 1166–1170 (2024). https://doi.org/10.1038/s41592-024-02299-2

Wickham, H., Vaughan, D. (2023). tidyr: Tidy Messy Data. R package version 2.0.0, https://CRAN.R-project.org/package=tidyr

See also

separate() to split up by a separator.

Examples

tidySummarizedExperiment::pasilla |>
    extract(type, into="sequencing", regex="([a-z]*)_end", convert=TRUE)
#> # A SummarizedExperiment-tibble abstraction: Features=14599 | Samples=7 | 
#> #   Assays=counts
#> #                                   |------ COVARIATES ----|
#>        .feature    .sample | counts | condition sequencing |
#>        <chr>       <chr>   | <chr>  | <chr>     <chr>      |
#> 1      FBgn0000003 untrt1  | 0      | untreated single     |
#> 2      FBgn0000008 untrt1  | 92     | untreated single     |
#> 3      FBgn0000014 untrt1  | 5      | untreated single     |
#> 4      FBgn0000015 untrt1  | 0      | untreated single     |
#> 5      FBgn0000017 untrt1  | 4664   | untreated single     |
#>        --------    ------- - ------ - --------- ---------- -
#> 102189 FBgn0261571 trt3    | 0      | treated   paired     |
#> 102190 FBgn0261572 trt3    | 3      | treated   paired     |
#> 102191 FBgn0261573 trt3    | 1908   | treated   paired     |
#> 102192 FBgn0261574 trt3    | 3047   | treated   paired     |
#> 102193 FBgn0261575 trt3    | 4      | treated   paired     |