-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
Creating knit_print.foo method does not work in R 3.5 #1580
Comments
Thanks for the report! I was aware of it when R 3.5.0 was released, but haven't had a chance to investigate it. I think you are correct that the S3 dispatch mechanism has changed somehow. |
We had to make a number of changes in RStudio to accommodate this: Not sure if it's helpful here, but our (very gross) workaround was to patch the S3 methods table directly: |
Yuck, that's unfortunate that there's no way to easily add a temporary S3 method now. EDIT: I mean, unless you have access to the correct environment. For reference, here's the NEWS item that Jonathan referenced in the issue that Kevin linked to (https://github.com/wch/r-source/blob/tags/R-3-5-0/doc/NEWS.Rd#L312):
I think the problem is that the knitr namespace is a top-level environment (see |
Just for info: I encountered a variant of this problem. My custom Below is an example code. It can also be tested https://rstudio.cloud/project/137636 # Restart R session if you load / unload rmarkdown
# Custom knit_print.data.frame only works if rmarkdown is not loaded
# library(rmarkdown)
library(knitr)
knit_print.data.frame = function (x, options = NULL, ...) {
asis_output("Custom Data Frame Printer!")
}
txt = "
```{r}
data.frame(x=1,y=2)
```"
html = knit2html(text=txt,fragment.only=TRUE)
html The work around with |
Yes, I should definitely update the vignette, and I need some helping hands... |
I don't know whether that counts as a helping hand. But until some other resolution is found, you could e.g. just change lines 40-50 in https://github.com/yihui/knitr/blob/master/vignettes/knit_print.Rmd by the following new lines. Note that if
|
Thanks @skranz! That was helpful. I just clarified in the vignette that |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
Example:
In R 3.4.4 (on rstudio.cloud), I get this:
In R 3.5.0 (on rstudio.cloud and on my local mac), I get:
I believe it must be due to a change in how S3 dispatch works.
A workaround is to use
registerS3method
.Here's an example that prints some more information and uses
registerS3method
.R 3.4.4:
R 3.5.0:
The text was updated successfully, but these errors were encountered: