@@ -29,14 +29,7 @@ arrange.SingleCellExperiment <- function(.data, ..., .by_group=FALSE) {
29
29
# ' @name bind_rows
30
30
# ' @rdname bind_rows
31
31
# ' @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
40
33
# '
41
34
# ' @references
42
35
# ' 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) {
48
41
# ' @importFrom SingleCellExperiment cbind
49
42
# ' @export
50
43
bind_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
+
51
51
tts <- flatten_if(dots_values(... ), is_spliced )
52
52
53
53
new_obj <- SingleCellExperiment :: cbind(tts [[1 ]], tts [[2 ]])
@@ -62,6 +62,45 @@ bind_rows.SingleCellExperiment <- function(..., .id=NULL, add.cell.ids=NULL) {
62
62
new_obj
63
63
}
64
64
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
+
65
104
# ' @importFrom rlang flatten_if
66
105
# ' @importFrom rlang is_spliced
67
106
# ' @importFrom rlang dots_values
0 commit comments