Skip to content

Commit

Permalink
Register Enhances S3 methods more selectively
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Dec 3, 2024
1 parent 0103bad commit eeb3215
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ default_settings <- NULL

settings <- new.env(parent = emptyenv())

enhances_method_registration <- function(generic, s3class, implementation, owner_package) {
# don't try requireNamespace(), which will load the package (with any associated side-effects).
if (isNamespaceLoaded(owner_package)) {
registerS3method(generic, s3class, implementation, asNamespace(owner_package))
return(invisible())
}
setHook(packageEvent(owner_package, "onLoad"), function(...) {
registerS3method(generic, s3class, implementation, envir = asNamespace(owner_package))
})
}

# nocov start
.onLoad <- function(libname, pkgname) {
op <- options()
Expand Down Expand Up @@ -330,11 +341,7 @@ settings <- new.env(parent = emptyenv())

reset_settings()

if (requireNamespace("tibble", quietly = TRUE)) {
registerS3method("as_tibble", "lints", as_tibble.lints, asNamespace("tibble"))
}
if (requireNamespace("data.table", quietly = TRUE)) {
registerS3method("as.data.table", "lints", as.data.table.lints, asNamespace("data.table"))
}
enhances_method_registration( "as_tibble", "lints", as_tibble.lints, "tibble")

Check warning on line 344 in R/zzz.R

View workflow job for this annotation

GitHub Actions / lint

file=R/zzz.R,line=344,col=32,[spaces_inside_linter] Do not place spaces after parentheses.
enhances_method_registration("as.data.table", "lints", as.data.table.lints, "data.table")
}
# nocov end

0 comments on commit eeb3215

Please sign in to comment.