Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly register knit_print S3 methods #108

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Package: htmltools
Type: Package
Title: Tools for HTML
Version: 0.3.6.9001
Date: 2017-04-26
Version: 0.3.6.9002
Author: RStudio, Inc.
Maintainer: Joe Cheng <joe@rstudio.com>
Description: Tools for HTML generation and output.
Expand Down
6 changes: 5 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
htmltools 0.3.6.9001
htmltools 0.3.6.9002
--------------------------------------------------------------------------------

* The `knit_print` methods are explicitly registered as S3 methods when both
knitr and htmltools are loaded. This means that neither shiny nor htmltools
need to be attached for the `knit_print` methods to work. (#108)

* Updated RcppExports for new version of Rcpp. (#93)

* `as.character.shiny.tags()` will handle non-ASCII attributes correctly if they
Expand Down
30 changes: 30 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
register_s3_method <- function(pkg, generic, class, fun = NULL) {
stopifnot(is.character(pkg), length(pkg) == 1)
stopifnot(is.character(generic), length(generic) == 1)
stopifnot(is.character(class), length(class) == 1)

if (is.null(fun)) {
fun <- get(paste0(generic, ".", class), envir = parent.frame())
} else {
stopifnot(is.function(fun))
}

if (pkg %in% loadedNamespaces()) {
registerS3method(generic, class, fun, envir = asNamespace(pkg))
}

# Always register hook in case package is later unloaded & reloaded
setHook(
packageEvent(pkg, "onLoad"),
function(...) {
registerS3method(generic, class, fun, envir = asNamespace(pkg))
}
)
}


.onLoad <- function(...) {
register_s3_method("knitr", "knit_print", "shiny.tag")
register_s3_method("knitr", "knit_print", "html")
register_s3_method("knitr", "knit_print", "shiny.tag.list")
}