Similar to how you can write _repr_html_ for a repr on an object in Python, I'd like to be able to decorate objects in R for inspection with the IRKernel (while not interfering with regular R usage of the library). How should I be writing R to make it nicer for Jupyter users?
The main kind of classes in R are S3 classes, and these are what IRKernel's repr library knows about.
Methods on S3 classes are more like generic functions. repr declares a number of generic functions like repr_html. If you define a class called frob, you can provide a function called repr_html.frob which returns the HTML to represent your object. All the magic for method lookup is based on the name, as far as I know, so you can define the repr_html.frob function as normal - it doesn't matter what package it's in, so long as the user loads the package before the kernel tries to display your object.
The generic functions repr declares are:
As in Python, you can define as many or as few of these as makes sense. See the repr code for some examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With