Skip to content

Instantly share code, notes, and snippets.

@krassowski
Last active March 17, 2019 03:00
Show Gist options
  • Save krassowski/0f810bf41cb3f785076b1fa1e3e9ac0b to your computer and use it in GitHub Desktop.
Save krassowski/0f810bf41cb3f785076b1fa1e3e9ac0b to your computer and use it in GitHub Desktop.
R (rpy2) autocompletion in Jupyter for IPython
from rpy2.robjects import r
from IPython import get_ipython
def rpy2_completer(ipython, event):
query = event.line.strip().split()[-1]
suggestions = []
all_r_symbols = r('sapply(search(), ls)')
for environment, symbols in all_r_symbols.items():
for _, symbol in symbols.items():
if symbol.startswith(query):
suggestions.append(symbol)
return suggestions
get_ipython().set_hook('complete_command', rpy2_completer, re_key='.*')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment