unnest

unnest_single_cell_experiment

# S3 method for tidySingleCellExperiment_nested
unnest(
  data,
  cols,
  ...,
  keep_empty = FALSE,
  ptype = NULL,
  names_sep = NULL,
  names_repair = "check_unique",
  .drop,
  .id,
  .sep,
  .preserve
)

unnest_single_cell_experiment(
  data,
  cols,
  ...,
  keep_empty = FALSE,
  ptype = NULL,
  names_sep = NULL,
  names_repair = "check_unique",
  .drop,
  .id,
  .sep,
  .preserve
)

Arguments

data

A tbl. (See tidyr)

cols

<tidy-select> Columns to unnest. If you unnest() multiple columns, parallel entries must be of compatible sizes, i.e. they're either equal or length 1 (following the standard tidyverse recycling rules).

...

<tidy-select> Columns to nest, specified using name-variable pairs of the form new_col=c(col1, col2, col3). The right hand side can be any valid tidy select expression.

[Deprecated] : previously you could write df %>% nest(x, y, z) and df %>% unnest(x, y, z). Convert to df %>% nest(data=c(x, y, z)). and df %>% unnest(c(x, y, z)).

If you previously created new variable in unnest() you'll now need to do it explicitly with mutate(). Convert df %>% unnest(y=fun(x, y, z)) to df %>% mutate(y=fun(x, y, z)) %>% unnest(y).

keep_empty

See tidyr::unnest

ptype

See tidyr::unnest

names_sep

If NULL, the default, the names will be left as is. In nest(), inner names will come from the former outer names; in unnest(), the new outer names will come from the inner names.

If a string, the inner and outer names will be used together. In nest(), the names of the new outer columns will be formed by pasting together the outer and the inner column names, separated by names_sep. In unnest(), the new inner names will have the outer names (+ names_sep) automatically stripped. This makes names_sep roughly symmetric between nesting and unnesting.

names_repair

See tidyr::unnest

.drop

See tidyr::unnest

.id

tidyr::unnest

.sep

tidyr::unnest

.preserve

See tidyr::unnest

sep

tidyr::unnest

Value

A tidySingleCellExperiment objector a tibble depending on input

A tidySingleCellExperiment objector a tibble depending on input

Examples


library(dplyr)
pbmc_small %>%

    nest(data=-groups) %>%
    unnest(data)
#> # A SingleCellExperiment-tibble abstraction: 80 × 17
#> # Features=230 | Cells=80 | Assays=counts, logcounts
#>    .cell        orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents
#>    <chr>        <fct>           <dbl>        <int> <fct>           <fct>        
#>  1 ATGCCAGAACG… SeuratPro…         70           47 0               A            
#>  2 GAACCTGATGA… SeuratPro…         87           50 1               B            
#>  3 TGACTGGATTC… SeuratPro…        127           56 0               A            
#>  4 AGTCAGACTGC… SeuratPro…        173           53 0               A            
#>  5 AGGTCATGAGT… SeuratPro…         62           31 0               A            
#>  6 GGGTAACTCTA… SeuratPro…        101           41 0               A            
#>  7 CATGAGACACG… SeuratPro…         51           26 0               A            
#>  8 TACGCCACTCC… SeuratPro…         99           45 0               A            
#>  9 GTAAGCACTCA… SeuratPro…         67           33 0               A            
#> 10 TACATCACGCT… SeuratPro…        109           41 0               A            
#> # ℹ 70 more rows
#> # ℹ 11 more variables: RNA_snn_res.1 <fct>, file <chr>, ident <fct>,
#> #   groups <chr>, PC_1 <dbl>, PC_2 <dbl>, PC_3 <dbl>, PC_4 <dbl>, PC_5 <dbl>,
#> #   tSNE_1 <dbl>, tSNE_2 <dbl>


library(dplyr)
pbmc_small %>%

    nest(data=-groups) %>%
    unnest_single_cell_experiment(data)
#> # A SingleCellExperiment-tibble abstraction: 80 × 17
#> # Features=230 | Cells=80 | Assays=counts, logcounts
#>    .cell        orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents
#>    <chr>        <fct>           <dbl>        <int> <fct>           <fct>        
#>  1 ATGCCAGAACG… SeuratPro…         70           47 0               A            
#>  2 GAACCTGATGA… SeuratPro…         87           50 1               B            
#>  3 TGACTGGATTC… SeuratPro…        127           56 0               A            
#>  4 AGTCAGACTGC… SeuratPro…        173           53 0               A            
#>  5 AGGTCATGAGT… SeuratPro…         62           31 0               A            
#>  6 GGGTAACTCTA… SeuratPro…        101           41 0               A            
#>  7 CATGAGACACG… SeuratPro…         51           26 0               A            
#>  8 TACGCCACTCC… SeuratPro…         99           45 0               A            
#>  9 GTAAGCACTCA… SeuratPro…         67           33 0               A            
#> 10 TACATCACGCT… SeuratPro…        109           41 0               A            
#> # ℹ 70 more rows
#> # ℹ 11 more variables: RNA_snn_res.1 <fct>, file <chr>, ident <fct>,
#> #   groups <chr>, PC_1 <dbl>, PC_2 <dbl>, PC_3 <dbl>, PC_4 <dbl>, PC_5 <dbl>,
#> #   tSNE_1 <dbl>, tSNE_2 <dbl>