Skip to content

Instantly share code, notes, and snippets.

@a-f-s-i-s
Created June 18, 2015 07:42
Show Gist options
  • Save a-f-s-i-s/59f25974fda1ba08fd39 to your computer and use it in GitHub Desktop.
Save a-f-s-i-s/59f25974fda1ba08fd39 to your computer and use it in GitHub Desktop.
rkernel hack code from ipython
"""A "native" IPython R kernel in 15 lines of code.
This isn't a real native R kernel, just a quick and dirty hack to get the
basics running in a few lines of code.
Put this into your startup directory for a profile named 'rkernel' or somesuch,
and upon startup, the kernel will imitate an R one by simply prepending `%%R`
to every cell.
"""
from IPython.core.interactiveshell import InteractiveShell
print '*** Initializing R Kernel ***'
ip = get_ipython()
ip.run_line_magic('load_ext', 'rpy2.ipython')
ip.run_line_magic('config', 'Application.verbose_crash=True')
old_run_cell = InteractiveShell.run_cell
def run_cell(self, raw_cell, **kw):
return old_run_cell(self, '%%R\n' + raw_cell, **kw)
InteractiveShell.run_cell = run_cell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment