diff --git a/NAMESPACE b/NAMESPACE index e73297a..2fe5fb9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,10 +3,11 @@ S3method("[",fcwtr_scalogram) S3method(as.data.frame,fcwtr_scalogram) S3method(as.matrix,fcwtr_scalogram) +S3method(ggplot2::autoplot,fcwtr_scalogram) S3method(plot,fcwtr_scalogram) S3method(print,fcwtr_scalogram) S3method(rbind,fcwtr_scalogram) -export(autoplot.fcwtr_scalogram) +S3method(tibble::as_tibble,fcwtr_scalogram) export(fcwt) export(fcwt_batch) export(u) diff --git a/R/fcwtr_scalogram.R b/R/fcwtr_scalogram.R index ae4f978..e479a57 100644 --- a/R/fcwtr_scalogram.R +++ b/R/fcwtr_scalogram.R @@ -335,6 +335,7 @@ as.data.frame.fcwtr_scalogram <- function(x, ...) { ) } +#' @exportS3Method tibble::as_tibble as_tibble.fcwtr_scalogram <- function(x, ...) { stopifnot(requireNamespace("tibble", quietly = TRUE)) @@ -490,7 +491,7 @@ plot.fcwtr_scalogram <- function(x, n = 1000, time_unit = "s", freq_unit = "Hz", #' #' autoplot(res, time_unit = "ms") #' -#' @export +#' @exportS3Method ggplot2::autoplot autoplot.fcwtr_scalogram <- function(object, n = 1000, time_unit = "s", freq_unit = "Hz", ...) { stopifnot(requireNamespace("ggplot2", quietly = TRUE)) diff --git a/R/zzz.R b/R/zzz.R deleted file mode 100644 index f63056a..0000000 --- a/R/zzz.R +++ /dev/null @@ -1,65 +0,0 @@ -s3_register <- - function(generic, class, method = NULL) { - stopifnot(is.character(generic), length(generic) == 1) - stopifnot(is.character(class), length(class) == 1) - pieces <- strsplit(generic, "::")[[1]] - stopifnot(length(pieces) == 2) - package <- pieces[[1]] - generic <- pieces[[2]] - caller <- parent.frame() - get_method_env <- function() { - top <- topenv(caller) - if (isNamespace(top)) { - asNamespace(environmentName(top)) - } else { - caller - } - } - get_method <- function(method) { - if (is.null(method)) { - get(paste0(generic, ".", class), envir = get_method_env()) - } else { - method - } - } - register <- function(...) { - envir <- asNamespace(package) - method_fn <- get_method(method) - stopifnot(is.function(method_fn)) - if (exists(generic, envir)) { - registerS3method(generic, class, method_fn, envir = envir) - } else if (identical(Sys.getenv("NOT_CRAN"), "true")) { - # warn <- .rlang_s3_register_compat("warn") - warning(c( - sprintf( - "Can't find generic `%s` in package %s to register S3 method.", - generic, package - ), - i = "This message is only shown to developers using devtools.", - i = sprintf( - "Do you need to update %s to the latest version?", - package - ) - )) - } - } - setHook(packageEvent(package, "onLoad"), function(...) { - register() - }) - is_sealed <- function(pkg) { - identical(pkg, "base") || environmentIsLocked(asNamespace(pkg)) - } - if (isNamespaceLoaded(package) && is_sealed(package)) { - register() - } - invisible() - } - -.onLoad <- function(...) { - if (requireNamespace("ggplot2", quietly = TRUE)) { - s3_register("ggplot2::autoplot", "fcwtr_scalogram") - } - if (requireNamespace("tibble", quietly = TRUE)) { - s3_register("tibble::as_tibble", "fcwtr_scalogram") - } -} diff --git a/man/autoplot.fcwtr_scalogram.Rd b/man/autoplot.fcwtr_scalogram.Rd index b7baae2..6fd9ac7 100644 --- a/man/autoplot.fcwtr_scalogram.Rd +++ b/man/autoplot.fcwtr_scalogram.Rd @@ -4,13 +4,7 @@ \alias{autoplot.fcwtr_scalogram} \title{Create a ggplot object resembling a scalogram} \usage{ -autoplot.fcwtr_scalogram( - object, - n = 1000, - time_unit = "s", - freq_unit = "Hz", - ... -) +\method{autoplot}{fcwtr_scalogram}(object, n = 1000, time_unit = "s", freq_unit = "Hz", ...) } \arguments{ \item{object}{A "fcwtr_scalogram" object resulting from \code{\link[=fcwt]{fcwt()}}.}