[R-pkg-devel] Registering methods conditionally

Lluís Revilla ||u|@@rev|||@ @end|ng |rom gm@||@com
Sat Feb 8 19:18:59 CET 2025


Dear list,

Checks of the package BaseSet I maintain are failing on r-devel with:
  Error in UseMethod("tidy") : no applicable method for 'tidy' applied to
an object of class "GeneSet" Calls: tidy Execution halted
Surprisingly, similar code on tests pass without errors.

This GeneSet is a S4 class exported by GSEABase and has been exported for
several years [1]. tidy is a S3 method defined on the package.

As this package is a suggested package, following WRE recommendations [2] I
tried to register the method conditionally under requireNamespace:

if (requireNamespace("GSEABase", quietly = TRUE)) {
importClassesFrom(GSEABase, GeneSetCollection)
S3method(tidy, GeneSetCollection)
importClassesFrom(GSEABase, GeneSet)
S3method(tidy, GeneSet)
importClassesFrom(GSEABase, CollectionType)
S3method(tidy, CollectionType)
}

However, the new NAMESPACE doesn't pass checks:
* checking package dependencies ... ERROR
Namespace dependency missing from DESCRIPTION Imports/Depends entries:
‘GSEABase’

There have been some threads on r-devel about registering dependencies to
classes defined in other packages [3]. I also saw some packages that
register the S3 method via .onLoad [4]. In this package I defined several
S3 methods for an S4 class. Should I define S4 methods for S4 classes not
defined in my package?

I would appreciate some advice on how to proceed,

Lluís


[1]: https://code.bioconductor.org/browse/GSEABase/blob/devel/NAMESPACE#L66
[2]:
https://cran.r-project.org/doc/manuals/R-exts.html#Specifying-imports-and-exports
[3]: https://stat.ethz.ch/pipermail/r-devel/2025-January/083780.html
[4]: https://vctrs.r-lib.org/reference/s3_register.html

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list