Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to do Jupyter cell magic with R

I have installed Jupyter and R on my Windows 8 laptop (64bit).

How do I run magic commands in a Jupyter notebook running with the R kernel.

Example: I would like to run e.g.

%%latex
\sqrt{2}

but instead of formatted math this returns:

Error in parse(text = x, srcfile = src): <text>:1:1: unexpected SPECIAL
1: %%
    ^

The documentation for these functions is somewhat sparse and a lot of it has not been updated from the IPython documentation. Perhaps this functionality is not intended with r kernels.

like image 205
HansHarhoff Avatar asked Jan 12 '16 13:01

HansHarhoff


2 Answers

The magic system is specific to the IPython kernel and does not exist in the R kernel. Currently there are no plans to integrate such a system (= we more or less decided not to start a magic system in IRkernel).

If you want to display markdown (or html/images/...) from r code, you can use the functions provided by the IRdisplay package, like:

library(IRdisplay)
display_markdown("**Strong Text**\n\nA formula: $\\sqrt{x}$")
like image 145
Jan Katins Avatar answered Sep 19 '22 10:09

Jan Katins


For Latex in Jupyter you do not need R magic. You can select cell type in the top panel with icons. Change "code" to "Markdown" and type:

$$
\sqrt{2}
$$
like image 20
Dima Lituiev Avatar answered Sep 21 '22 10:09

Dima Lituiev