@@ -29,14 +29,7 @@ arrange.SingleCellExperiment <- function(.data, ..., .by_group=FALSE) {
2929# ' @name bind_rows
3030# ' @rdname bind_rows
3131# ' @inherit ttservice::bind_rows
32- # '
33- # ' @examples
34- # ' data(pbmc_small)
35- # ' tt <- pbmc_small
36- # ' bind_rows(tt, tt)
37- # '
38- # ' tt_bind <- tt |> select(nCount_RNA, nFeature_RNA)
39- # ' tt |> bind_cols(tt_bind)
32+ # ' @noRd
4033# '
4134# ' @references
4235# ' 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
@@ -48,6 +41,13 @@ arrange.SingleCellExperiment <- function(.data, ..., .by_group=FALSE) {
4841# ' @importFrom SingleCellExperiment cbind
4942# ' @export
5043bind_rows.SingleCellExperiment <- function (... , .id = NULL , add.cell.ids = NULL ) {
44+ lifecycle :: deprecate_warn(
45+ when = " 1.19.2" ,
46+ what = " bind_rows()" ,
47+ with = " append_samples()" ,
48+ details = " bind_rows is not a generic method in dplyr and may cause conflicts. Use append_samples."
49+ )
50+
5151 tts <- flatten_if(dots_values(... ), is_spliced )
5252
5353 new_obj <- SingleCellExperiment :: cbind(tts [[1 ]], tts [[2 ]])
@@ -62,6 +62,45 @@ bind_rows.SingleCellExperiment <- function(..., .id=NULL, add.cell.ids=NULL) {
6262 new_obj
6363}
6464
65+ # ' @name append_samples
66+ # ' @rdname append_samples
67+ # ' @title Append samples from multiple SingleCellExperiment objects
68+ # '
69+ # ' @description
70+ # ' Append samples from multiple SingleCellExperiment objects by column-binding them.
71+ # ' This function is equivalent to `cbind` but provides a tidyverse-like interface.
72+ # '
73+ # ' @param x First SingleCellExperiment object to combine
74+ # ' @param ... Additional SingleCellExperiment objects to combine by samples
75+ # ' @param .id Object identifier (currently not used)
76+ # '
77+ # ' @return A combined SingleCellExperiment object
78+ # '
79+ # ' @examples
80+ # ' data(pbmc_small)
81+ # ' append_samples(pbmc_small, pbmc_small)
82+ # '
83+ # ' @importFrom ttservice append_samples
84+ # ' @importFrom rlang flatten_if
85+ # ' @importFrom rlang is_spliced
86+ # ' @importFrom SingleCellExperiment cbind
87+ # ' @export
88+ append_samples.SingleCellExperiment <- function (x , ... , .id = NULL ) {
89+ # Combine all arguments into a list
90+ tts <- flatten_if(list (x , ... ), is_spliced )
91+ new_obj <- do.call(cbind , tts )
92+
93+ # If duplicated cell names
94+ if (any(duplicated(colnames(new_obj )))) {
95+ warning(" tidySingleCellExperiment says:" ,
96+ " you have duplicated cell names, they will be made unique." )
97+ unique_colnames <- make.unique(colnames(new_obj ), sep = " _" )
98+ colnames(new_obj ) <- unique_colnames
99+ }
100+
101+ new_obj
102+ }
103+
65104# ' @importFrom rlang flatten_if
66105# ' @importFrom rlang is_spliced
67106# ' @importFrom rlang dots_values
0 commit comments