Skip to content

Commit 92cc7f7

Browse files
authored
Merge pull request #55 from stemangiola/add_count-drop-generics
Add count drop generics
2 parents 1cd396d + 4ab0f70 commit 92cc7f7

File tree

6 files changed

+71
-136
lines changed

6 files changed

+71
-136
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: tidySingleCellExperiment
33
Title: Brings SingleCellExperiment to the Tidyverse
4-
Version: 1.9.2
4+
Version: 1.9.3
55
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
66
role = c("aut", "cre")) )
77
Description: tidySingleCellExperiment is an adapter that abstracts the 'SingleCellExperiment' container

NAMESPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method(add_count,SingleCellExperiment)
4-
S3method(add_count,default)
54
S3method(arrange,SingleCellExperiment)
65
S3method(as_tibble,SingleCellExperiment)
76
S3method(bind_cols,SingleCellExperiment)
87
S3method(bind_cols,default)
98
S3method(bind_rows,SingleCellExperiment)
109
S3method(bind_rows,default)
1110
S3method(count,SingleCellExperiment)
12-
S3method(count,default)
1311
S3method(distinct,SingleCellExperiment)
1412
S3method(extract,SingleCellExperiment)
1513
S3method(filter,SingleCellExperiment)
@@ -87,6 +85,7 @@ importFrom(SummarizedExperiment,"colData<-")
8785
importFrom(SummarizedExperiment,assays)
8886
importFrom(SummarizedExperiment,colData)
8987
importFrom(cli,cat_line)
88+
importFrom(dplyr,add_count)
9089
importFrom(dplyr,arrange)
9190
importFrom(dplyr,count)
9291
importFrom(dplyr,distinct)

R/dplyr_methods.R

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ sample_frac.SingleCellExperiment <- function(tbl, size=1, replace=FALSE,
12781278

12791279
#' Count observations by group
12801280
#'
1281+
#' @importFrom dplyr count
12811282
#'
12821283
#' @description
12831284
#' `count()` lets you quickly count the unique values of one or more variables:
@@ -1311,30 +1312,19 @@ sample_frac.SingleCellExperiment <- function(tbl, size=1, replace=FALSE,
13111312
#' An object of the same type as `.data`. `count()` and `add_count()`
13121313
#' group transiently, so the output has the same groups as the input.
13131314
#' @export
1315+
#'
1316+
#' @rdname dplyr-methods
1317+
#' @name count
1318+
#'
13141319
#' @examples
13151320
#'
1321+
#'
13161322
#' `%>%` <- magrittr::`%>%`
13171323
#' pbmc_small %>%
13181324
#'
13191325
#' count(groups)
1320-
count <- function(x, ..., wt=NULL, sort=FALSE, name=NULL, .drop=group_by_drop_default(x)) {
1321-
UseMethod("count")
1322-
}
1326+
NULL
13231327

1324-
#' @export
1325-
count.default <- function(x, ..., wt=NULL, sort=FALSE, name=NULL, .drop=group_by_drop_default(x)) {
1326-
if (!missing(...)) {
1327-
out <- dplyr::group_by(x, ..., .add=TRUE, .drop=.drop)
1328-
}
1329-
else {
1330-
out <- x
1331-
}
1332-
out <- dplyr::tally(out, wt=!!enquo(wt), sort=sort, name=name)
1333-
if (is.data.frame(x)) {
1334-
out <- dplyr::dplyr_reconstruct(out, x)
1335-
}
1336-
out
1337-
}
13381328
#' @export
13391329
count.SingleCellExperiment <- function(x, ..., wt=NULL, sort=FALSE, name=NULL, .drop=group_by_drop_default(x)) {
13401330
message(data_frame_returned_message)
@@ -1352,23 +1342,19 @@ count.SingleCellExperiment <- function(x, ..., wt=NULL, sort=FALSE, name=NULL, .
13521342
dplyr::count(..., wt=!!enquo(wt), sort=sort, name=name, .drop=.drop)
13531343
}
13541344

1355-
#' @export
1356-
#' @rdname count
1357-
add_count <- function(x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x)) {
1358-
UseMethod("add_count")
1359-
}
13601345

13611346
#' @export
1362-
#' @rdname count
1363-
add_count.default <- function(x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x)) {
1364-
1365-
dplyr::add_count(x=x, ..., wt = !!enquo(wt), sort = sort, name = name, .drop = .drop)
1366-
1367-
}
1347+
#'
1348+
#'
1349+
#' @importFrom dplyr add_count
1350+
#'
1351+
#' @name add_count
1352+
#'
1353+
#' @rdname dplyr-methods
1354+
NULL
13681355

13691356
#' @export
1370-
#' @rdname count
1371-
add_count.SingleCellExperiment <- function(x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x)) {
1357+
add_count.SingleCellExperiment <- function(x, ..., wt = NULL, sort = FALSE, name = NULL) {
13721358

13731359
# Deprecation of special column names
13741360
if(is_sample_feature_deprecated_used(
@@ -1378,16 +1364,18 @@ add_count.SingleCellExperiment <- function(x, ..., wt = NULL, sort = FALSE, name
13781364
x= ping_old_special_column_into_metadata(x)
13791365
}
13801366

1381-
colData(x) =
1382-
x %>%
1383-
as_tibble %>%
1384-
dplyr::add_count(..., wt = !!enquo(wt), sort = sort, name = name, .drop = .drop) %>%
1385-
as_meta_data(x)
1367+
colData(x) =
1368+
x %>%
1369+
as_tibble %>%
1370+
dplyr::add_count(..., wt = !!enquo(wt), sort = sort, name = name) %>%
1371+
as_meta_data(x)
13861372

1387-
x
1373+
x
13881374

13891375
}
13901376

1377+
1378+
13911379
#' Extract a single column
13921380
#'
13931381
#'

man/count.Rd

Lines changed: 0 additions & 92 deletions
This file was deleted.

man/dplyr-methods.Rd

Lines changed: 38 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-dplyr_methods.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,10 @@ test_that("count", {
172172
nrow() %>%
173173
expect_equal(2)
174174
})
175+
176+
test_that("add count", {
177+
pbmc_small %>%
178+
add_count(groups) %>%
179+
nrow() %>%
180+
expect_equal(230)
181+
})

0 commit comments

Comments
 (0)