1+ library(S4Vectors )
12data(pbmc_small )
23df <- pbmc_small
34df $ number <- sample(seq(ncol(df )))
@@ -130,6 +131,17 @@ test_that("left_join()", {
130131 expect_identical(colData(fd )[- n ], colData(df ))
131132})
132133
134+ test_that(" left_join(), with DataFrame y" , {
135+ y <- df | >
136+ distinct(factor ) | >
137+ mutate(string = letters [seq(nlevels(df $ factor ))]) | >
138+ DataFrame()
139+ fd <- left_join(df , y , by = " factor" )
140+ expect_s4_class(fd , " SingleCellExperiment" )
141+ expect_equal(n <- ncol(colData(fd )), ncol(colData(df ))+ 1 )
142+ expect_identical(colData(fd )[- n ], colData(df ))
143+ })
144+
133145test_that(" inner_join()" , {
134146 y <- df | >
135147 distinct(factor ) | >
@@ -141,6 +153,17 @@ test_that("inner_join()", {
141153 expect_equal(ncol(fd ), sum(df $ factor == fd $ factor [1 ]))
142154})
143155
156+ test_that(" inner_join(), with DataFrame y" , {
157+ y <- df | >
158+ distinct(factor ) | >
159+ mutate(string = letters [seq(nlevels(df $ factor ))]) | >
160+ slice(1 ) | > DataFrame()
161+ fd <- inner_join(df , y , by = " factor" )
162+ expect_s4_class(fd , " SingleCellExperiment" )
163+ expect_equal(n <- ncol(colData(fd )), ncol(colData(df ))+ 1 )
164+ expect_equal(ncol(fd ), sum(df $ factor == fd $ factor [1 ]))
165+ })
166+
144167test_that(" right_join()" , {
145168 y <- df | >
146169 distinct(factor ) | >
@@ -152,6 +175,17 @@ test_that("right_join()", {
152175 expect_equal(ncol(fd ), sum(df $ factor == fd $ factor [1 ]))
153176})
154177
178+ test_that(" right_join(), with DataFrame y" , {
179+ y <- df | >
180+ distinct(factor ) | >
181+ mutate(string = letters [seq(nlevels(df $ factor ))]) | >
182+ slice(1 ) | > DataFrame()
183+ fd <- right_join(df , y , by = " factor" )
184+ expect_s4_class(fd , " SingleCellExperiment" )
185+ expect_equal(n <- ncol(colData(fd )), ncol(colData(df ))+ 1 )
186+ expect_equal(ncol(fd ), sum(df $ factor == fd $ factor [1 ]))
187+ })
188+
155189test_that(" full_join()" , {
156190 # w/ duplicated cell names
157191 y <- tibble(factor = " g2" , other = 1 : 3 )
@@ -169,6 +203,23 @@ test_that("full_join()", {
169203 mutate(df , factor = paste(factor )))
170204})
171205
206+ test_that(" full_join(), with DataFrame y" , {
207+ # w/ duplicated cell names
208+ y <- tibble(factor = " g2" , other = 1 : 3 ) | > DataFrame()
209+ fd <- expect_message(full_join(df , y , by = " factor" , relationship = " many-to-many" ))
210+ expect_s3_class(fd , " tbl_df" )
211+ expect_true(all(is.na(fd $ other [fd $ factor != " g2" ])))
212+ expect_true(all(! is.na(fd $ other [fd $ factor == " g2" ])))
213+ expect_equal(nrow(fd ), ncol(df )+ 2 * sum(df $ factor == " g2" ))
214+ # w/o duplicates
215+ y <- tibble(factor = " g2" , other = 1 ) | > DataFrame()
216+ fd <- expect_silent(full_join(df , y , by = " factor" ))
217+ expect_s4_class(fd , " SingleCellExperiment" )
218+ expect_identical(
219+ select(fd , - other ),
220+ mutate(df , factor = paste(factor )))
221+ })
222+
172223test_that(" slice()" , {
173224 expect_identical(slice(df ), df [, 0 ])
174225 expect_identical(slice(df , ncol(df )+ 1 ), df [, 0 ])
0 commit comments