Skip to content

Commit 5a52ad9

Browse files
committed
Delay S3method(knit_print, data.table) for R < 3.6
Use setHook() to ensure that registerS3method() will be called in the same session if 'knitr' is loaded later. Not needed on R >= 3.6.0 where S3method(knitr::knit_print) will do the right thing by itself.
1 parent a2c9184 commit 5a52ad9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

R/onLoad.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
lockBinding("rbind.data.frame",baseenv())
6767
}
6868
}
69+
if (session_r_version < "3.6.0") {
70+
# no delayed registration support for NAMESPACE; perform it manually
71+
if (isNamespaceLoaded("knitr")) {
72+
registerS3method("knit_print", "data.table", knit_print.data.table, envir = asNamespace("knitr"))
73+
}
74+
setHook(packageEvent("knitr", "onLoad"), function(...) {
75+
registerS3method("knit_print", "data.table", knit_print.data.table, envir = asNamespace("knitr"))
76+
})
77+
}
6978

7079
# Set options for the speed boost in v1.8.0 by avoiding 'default' arg of getOption(,default=)
7180
# In fread and fwrite we have moved back to using getOption's default argument since it is unlikely fread and fread will be called in a loop many times, plus they

0 commit comments

Comments
 (0)