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

Replace conditional S3 method registration with NAMESPACE directive #400

Closed
MichaelChirico opened this issue Dec 3, 2024 · 3 comments
Closed

Comments

@MichaelChirico
Copy link

tinytable/R/zzz.R

Lines 1 to 5 in 2260238

.onLoad <- function(libname, pkgname) {
if(requireNamespace("knitr", quietly = TRUE)) {
registerS3method("knit_print", "tinytable", knit_print.tinytable, envir = asNamespace("knitr"))
}
}

Was searching around a bit after discovering the very nice approach in Rdatatable/data.table#6589 and found {tinytable}. Because {tinytable} depends on R>=4.1.0, this can be replaced by S3method(knitr::knit_print, tinytable).

I only didn't file the PR because I am not sure the right way to do so with {roxygen2} (do we need @rawNamespace?), and don't quite have time to dig deeper at the moment.

@vincentarelbundock
Copy link
Owner

Thanks for raising this issue. This looks interesting. I don't have time to figure this out now, but I'm definitely interested and will try to take a look when possible.

@vincentarelbundock
Copy link
Owner

Thanks again. This appears to work:

#' @rawNamespace S3method(knitr::knit_print, tinytable)

8fea197

@MichaelChirico
Copy link
Author

MichaelChirico commented Dec 12, 2024

Nice! FWIW we found roxygen2 has slightly cleaner support:

r-lib/lintr@c3d2935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants