Last active
March 17, 2019 03:00
-
-
Save krassowski/0f810bf41cb3f785076b1fa1e3e9ac0b to your computer and use it in GitHub Desktop.
R (rpy2) autocompletion in Jupyter for IPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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