R/tidyr_methods.R
separate.Rd
separate()
has been superseded in favour of separate_wider_position()
and separate_wider_delim()
because the two functions make the two uses
more obvious, the API is more polished, and the handling of problems is
better. Superseded functions will not go away, but will only receive
critical bug fixes.
Given either a regular expression or a vector of character positions,
separate()
turns a single character column into multiple columns.
# S3 method for class 'SummarizedExperiment'
separate(
data,
col,
into,
sep = "[^[:alnum:]]+",
remove = TRUE,
convert = FALSE,
extra = "warn",
fill = "warn",
...
)
A data frame.
<tidy-select
> Column to expand.
Names of new variables to create as character vector.
Use NA
to omit the variable in the output.
Separator between columns.
If character, sep
is interpreted as a regular expression. The default
value is a regular expression that matches any sequence of
non-alphanumeric values.
If numeric, sep
is interpreted as character positions to split at. Positive
values start at 1 at the far-left of the string; negative value start at -1 at
the far-right of the string. The length of sep
should be one less than
into
.
If TRUE
, remove input column from output data frame.
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 NA
s.
If sep
is a character vector, this controls what
happens when there are too many pieces. There are three valid options:
"warn"
(the default): emit a warning and drop extra values.
"drop"
: drop any extra values without a warning.
"merge"
: only splits at most length(into)
times
If sep
is a character vector, this controls what
happens when there are not enough pieces. There are three valid options:
"warn"
(the default): emit a warning and fill from the right
"right"
: fill with missing values on the right
"left"
: fill with missing values on the left
Additional arguments passed on to methods.
tidySummarizedExperiment
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
un <- tidySummarizedExperiment::pasilla |>
unite("group", c(condition, type))
#> tidySummarizedExperiment says: Key columns are missing. A data frame is returned for independent data analysis.
un |> separate(col=group, into=c("condition", "type"))
#> Warning: Expected 2 pieces. Additional pieces discarded in 7 rows [1, 2, 3, 4, 5, 6, 7].
#> class: SummarizedExperiment
#> dim: 14599 7
#> metadata(0):
#> assays(1): counts
#> rownames(14599): FBgn0000003 FBgn0000008 ... FBgn0261574 FBgn0261575
#> rowData names(0):
#> colnames(7): untrt1 untrt2 ... trt2 trt3
#> colData names(2): condition type