Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add native knitr print methods

Tags:

r

knitr

rnotebook

I'm looking for a way to adjust functions which usually show html tables in the viewer or browser in a way that they automatically insert the html in knitr documents like rnotebooks when called.

Specifically I want to change the way functions in the package sjPlot behave. At the moment they return an object with a $knitr attribute that has to be inserted manually and then produce an html table in the viewer:

`r sjt.frq(efc$e42dep, no.output=TRUE)$knitr`

One of these functions is sjt.frq. Is there a way to do this?

like image 345
methodds Avatar asked Jan 25 '26 17:01

methodds


1 Answers

From knit_print:

library(knitr)
a = 42
class(a) = "my_class"
knit_print.my_class = function(x,...){
    res = paste("{{", x,"}}")
    asis_output(res)
}
a

It works when I knit document but doesn't work with RNotebooks and doesn't work with sjt.frq. However with RNotebook works the following statement:

library(sjPlot)
library(sjmisc)
library(knitr)

data(efc)
asis_output(sjt.frq(efc$e42dep, no.output=TRUE)$knitr)
like image 165
Gregory Demin Avatar answered Jan 28 '26 08:01

Gregory Demin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!