Skip to content

Commit

Permalink
Adds @export to internal S3 methods so that they are registered & fou…
Browse files Browse the repository at this point in the history
…nd properly.

We were getting hosed during unit testing because R v4.0.x chnaged the way
S3 generics are found, and we now have to add an `@export` roxygen tag to
internal S3 functions for things to work like before.

Here is a more thorough / accurate discussion of the topic and suggested
fix which was implemented in this commit:

r-lib/devtools#2293
  • Loading branch information
lianos committed Dec 1, 2020
1 parent cd8a1d4 commit df12f38
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
uses: actions/checkout@v2

- name: Setup R
uses: r-lib/actions/setup-r@2fac31217e602dd30286b4c984a0ccf1afb18cbd
# uses: r-lib/actions/setup-r@master
# with:
# install-r: false
# uses: r-lib/actions/setup-r@2fac31217e602dd30286b4c984a0ccf1afb18cbd
uses: r-lib/actions/setup-r@v1
with:
install-r: false

# pandoc is already installed in the docker container
# - uses: r-lib/actions/setup-pandoc@master
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: FacileData
Type: Package
Title: A fluent API for accessing multi-assay high-throughput genomics data
Version: 0.11.7
Version: 0.11.8
Authors@R: c(
person("Steve", "Lianoglou", , "lianoglou@dnli.com", c("aut", "cre"),
comment = c(ORCID = "0000-0002-0924-1754")),
Expand Down
18 changes: 18 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
S3method("fds<-",data.frame)
S3method("fds<-",default)
S3method("fds<-",tbl)
S3method(adata,DGEList)
S3method(adata,EList)
S3method(adata,ExpressionSet)
S3method(adata,SummarizedExperiment)
S3method(anti_join,facile_frame)
S3method(arrange,facile_frame)
S3method(as.DGEList,FacileDataSet)
S3method(as.DGEList,data.frame)
S3method(as.DGEList,facile_frame)
S3method(as.DGEList,matrix)
S3method(as.DGEList,tbl)
S3method(as.ExpressionSet,FacileDataSet)
S3method(as.ExpressionSet,data.frame)
Expand All @@ -28,8 +33,15 @@ S3method(covariate_definitions,FacileDataSet)
S3method(default_assay,FacileDataSet)
S3method(default_assay,default)
S3method(distinct,facile_frame)
S3method(ds_annot,ExpressionSet)
S3method(ds_annot,SummarizedExperiment)
S3method(ds_annot,default)
S3method(facet_frame,FacileDataSet)
S3method(facet_frame,default)
S3method(fdata,DGEList)
S3method(fdata,EList)
S3method(fdata,ExpressionSet)
S3method(fdata,SummarizedExperiment)
S3method(fds,FacileDataStore)
S3method(fds,default)
S3method(features,FacileDataSet)
Expand All @@ -41,6 +53,7 @@ S3method(fetch_assay_score,default)
S3method(fetch_custom_sample_covariates,FacileDataSet)
S3method(fetch_custom_sample_covariates,default)
S3method(fetch_feature_info,FacileDataSet)
S3method(fetch_feature_info,default)
S3method(fetch_sample_covariates,FacileDataSet)
S3method(fetch_sample_covariates,default)
S3method(fetch_sample_covariates,facile_frame)
Expand All @@ -67,6 +80,10 @@ S3method(name,FacileDataSet)
S3method(organism,FacileDataSet)
S3method(organism,default)
S3method(organism,facile_frame)
S3method(pdata,DGEList)
S3method(pdata,EList)
S3method(pdata,ExpressionSet)
S3method(pdata,SummarizedExperiment)
S3method(pdata_metadata,DGEList)
S3method(pdata_metadata,EList)
S3method(pdata_metadata,ExpressionSet)
Expand All @@ -89,6 +106,7 @@ S3method(ungroup,facile_frame)
S3method(with_assay_covariates,data.frame)
S3method(with_assay_covariates,facile_frame)
S3method(with_assay_data,data.frame)
S3method(with_assay_data,default)
S3method(with_assay_data,facile_frame)
S3method(with_assay_data,tbl)
S3method(with_feature_info,data.frame)
Expand Down
4 changes: 4 additions & 0 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ fetch_feature_info <- function(x, feature_type, feature_ids = NULL, ...) {
UseMethod("fetch_feature_info", x)
}

#' @noRd
#' @export
fetch_feature_info.default <- function(x, feature_type, feature_ids = NULL, ...) {
stop("Implement fetch_feature_info for class: ", class(x)[1L])
}
Expand Down Expand Up @@ -581,6 +583,8 @@ with_assay_data <- function(x, features, assay_name = NULL,
UseMethod("with_assay_data", x)
}

#' @noRd
#' @export
with_assay_data.default <- function(x, features, assay_name = NULL,
normalized = TRUE, aggregate = FALSE,
aggregate.by = "ewm",
Expand Down
6 changes: 4 additions & 2 deletions R/as.BiocAssayContainers.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ as.DGEList <- function(x, ...) {
}

#' @noRd
#' @export
#' @method as.DGEList matrix
#' @rdname as.BiocContainer
#' @importFrom edgeR DGEList calcNormFactors
Expand Down Expand Up @@ -164,8 +165,9 @@ as.DGEList.matrix <- function(x, covariates = TRUE, feature_ids = NULL,
is.neg <- which(x < 0, arr.ind = TRUE)
if (nrow(is.neg)) x[is.neg] <- x[is.neg] * -1

y <- DGEList(x, genes = genes, lib.size = sample.stats[["libsize"]],
norm.factors = sample.stats[["normfactor"]])
y <- DGEList(x, genes = genes, lib.size = sample.stats[["libsize"]])
# This avoids the warning when norm factors don't multiply to 1
y$samples$norm.factors <- sample.stats[["normfactor"]]

y$samples <- cbind(
y$samples,
Expand Down
44 changes: 37 additions & 7 deletions R/as.FacileDataSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ as.FacileDataSet.list <- function(x, path, assay_name, assay_type,
#' no such slot, unfortunately, and thus gets the default. SE has a
#' metadata slot and can provide url and description. eSet just has
#' a character annotation and can provide a description.
#'
#' This is an internal helper function.
#'
#' @param x SummarizedExperiment, ExpressionSet or DGEList
#' @param validate single logical, check results
#' @param meta a list of description stuff for the dataset, this can act to
Expand All @@ -311,6 +314,8 @@ ds_annot <- function(x, meta = NULL, validate = FALSE, ...) {
UseMethod("ds_annot")
}

#' @noRd
#' @export
ds_annot.SummarizedExperiment <- function(x, meta = NULL, validate = FALSE,
...) {
ns4 <- tryCatch(loadNamespace("S4Vectors"), error = function(e) NULL)
Expand All @@ -321,12 +326,16 @@ ds_annot.SummarizedExperiment <- function(x, meta = NULL, validate = FALSE,
out
}

#' @noRd
#' @export
ds_annot.ExpressionSet <- function(x, meta = NULL, validate = FALSE, ...) {
out <- .merge_ds_annot(NULL, meta)
if (validate) .ds_annot_validate(out)
out
}

#' @noRd
#' @export
ds_annot.default <- function(x, meta = NULL, validate = FALSE, ...) {
out <- .merge_ds_annot(NULL, meta)
if (validate) .ds_annot_validate(out)
Expand Down Expand Up @@ -359,35 +368,45 @@ ds_annot.default <- function(x, meta = NULL, validate = FALSE, ...) {

#' BioC-container specific fData extraction functions
#'
#' not for export
#' @param x SummarizedExperiment, ExpressionSet or DGEList
#' @param validate single logical, check results
#' @param ... additional args (ignored for now)
fdata <- function(x, validate = FALSE, ...) {
UseMethod("fdata")
}

#' @noRd
#' @export
fdata.SummarizedExperiment <- function(x, validate = FALSE, ...) {
ns <- tryCatch(loadNamespace("SummarizedExperiment"), error = function(e) NULL)
if (is.null(ns)) stop("SummarizedExperiment required")
ns4 <- tryCatch(loadNamespace("S4Vectors"), error = function(e) NULL)
if (is.null(ns4)) stop("S4Vectors required")

# out <- ns$as.data.frame(ns$mcols(x))
out <- ns4$as.data.frame.DataTable(ns$rowData(x))
out <- ns4$.as.data.frame.DataFrame(ns$rowData(x))
if (validate) validate.fdata(out, ...) else out
}

#' @noRd
#' @export
fdata.ExpressionSet <- function(x, validate = FALSE, ...) {
ns <- tryCatch(loadNamespace("Biobase"), error = function(e) NULL)
if (is.null(ns)) stop("Biobase required")

out <- ns$fData(x)
if (validate) validate.fdata(out, ...) else out
}

#' @noRd
#' @export
fdata.DGEList <- function(x, validate = FALSE, ...) {
# stopifnot(requireNamespace("edgeR", quietly = TRUE))
out <- x$genes
if (validate) validate.fdata(out, ...) else out
}

#' @noRd
#' @export
fdata.EList <- function(x, validate = FALSE, ...) {
out <- x$genes
if (validate) validate.fdata(out, ...) else out
Expand Down Expand Up @@ -425,33 +444,37 @@ validate.fdata <- function(x, ...) {

#' Bioc-container specific pData extraction functions
#'
#' not for export
#' This is an internal function, but exported so it is registered and found
#' post R 4.0
#' @param x SummarizedExperiment, ExpressionSet or DGEList
#' @param ... additional args, ignored for now
pdata <- function(x, covariate_metadata = NULL, ...) {
UseMethod("pdata")
UseMethod("pdata", x)
}

#' @noRd
#' @export
pdata.SummarizedExperiment <- function(x, covariate_metadata = NULL, ...) {
ns <- tryCatch(loadNamespace("SummarizedExperiment"), error = function(e) NULL)
if (is.null(ns)) stop("SummarizedExperiment required")
ns4 <- tryCatch(loadNamespace("S4Vectors"), error = function(e) NULL)
if (is.null(ns4)) stop("S4Vectors required")

df <- ns$colData(x)
ds <- ns4$as.data.frame.DataTable(df)
ds <- ns4$.as.data.frame.DataFrame(df)
validate.pdata(ds, ...)
}

#' @noRd
#' @export
pdata.ExpressionSet <- function(x, covariate_metadata = NULL, ...) {
ns <- tryCatch(loadNamespace("Biobase"), error = function(e) NULL)
if (is.null(ns)) stop("Biobase required")
validate.pdata(ns$pData(x), ...)
}

#' @noRd
#' @export
pdata.DGEList <- function(x, covariate_metadata = NULL, ...) {
# stopifnot(requireNamespace("edgeR", quietly = TRUE))
ignore.cols <- c("lib.size", "norm.factors")
Expand All @@ -463,10 +486,12 @@ pdata.DGEList <- function(x, covariate_metadata = NULL, ...) {
}

#' @noRd
#' @export
pdata.EList <- function(x, covariate_metadata = NULL, ...) {
validate.pdata(x$targets, ...)
}

#' @noRd
validate.pdata <- function(x, ...) {
x
}
Expand Down Expand Up @@ -530,13 +555,15 @@ pdata_metadata.EList <- function(x, ...) {
#' Bioc-container specific assay data extraction functions
#'
#' Get assay matrix
#'
#' @param x SummarizedExperiment, ExpressionSet or DGEList
#' @param ... additional args, ignored for now
adata <- function(x, assay = NULL, ...) {
UseMethod("adata")
UseMethod("adata", x)
}

#' @noRd
#' @export
adata.SummarizedExperiment <- function(x, assay = NULL, ...) {
ns <- tryCatch(loadNamespace("SummarizedExperiment"), error = function(e) NULL)
if (is.null(ns)) stop("SummarizedExperiment required")
Expand All @@ -549,6 +576,7 @@ adata.SummarizedExperiment <- function(x, assay = NULL, ...) {
}

#' @noRd
#' @export
adata.ExpressionSet <- function(x, assay = NULL, ...) {
ns <- tryCatch(loadNamespace("Biobase"), error = function(e) NULL)
if (is.null(ns)) stop("Biobase required")
Expand All @@ -561,13 +589,15 @@ adata.ExpressionSet <- function(x, assay = NULL, ...) {
}

#' @noRd
#' @export
adata.DGEList <- function(x, assay = NULL, ...) {
# stopifnot(requireNamespace("edgeR", quietly = TRUE))
# DGEList only has one assay
x$counts
}

#' @noRd
#' @export
adata.EList <- function(x, assay = NULL, ...) {
# EList only has one assay
x[["E"]]
Expand Down
2 changes: 1 addition & 1 deletion R/assay-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fetch_assay_data.FacileDataSet <- function(x, features, samples = NULL,

#' @export
#' @noRd
fetch_assay_data.facile_frame <- function(x, features, samples = NULL,
fetch_assay_data.facile_frame <- function(x, features = NULL, samples = NULL,
assay_name = NULL,
normalized = FALSE,
batch = NULL, main = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/biocbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ biocbox.FacileDataStore <- function(x, class = NULL, assay_name = NULL,
#' DGEList lib.size calculated from the data that made its way into the DGEList)
#'
#' @export
#'
#' @rdname biocbox
#' @param sample_covariates If `NULL` (default), all sample covariates will
#' be included over samples in x. If a data.frame, we will treat the
#' extra columns as custom covariates, and include them in the outgoing
Expand Down
2 changes: 1 addition & 1 deletion man/FacileData-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion man/biocbox.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/ds_annot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fdata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df12f38

Please sign in to comment.