ValueError: call stack is not deep enough

Issue #184 invalid
Laurent Gautier
created an issue

The following code triggers a ValueError: call stack is not deep enough (error at the last line0 whenever it is run it is run in python. There is no error when runnig it through ipython (either interactive or batch).

from IPython.testing.globalipapp import get_ipython
ip.magic('load_ext rpy2.ipython')
ip.push({'x': 0})
ip.run_line_magic('R', '-i x -o result result <-x+1')

Comments (6)

  1. Thomas Kluyver

    When you run a magic, IPython can interpolate Python variables into the magic command before evaluating it. In order to access local variables if you call a magic inside a Python function, it looks back up the stack. Normally, inside IPython, the stack would look contain:

    • ...
    • user function (where we want to get local variables)
    • ip.magic()
    • ip.run_line_magic()
    • ip.var_expand()

    So it looks three levels up. In the specific situation of calling ip.run_line_magic() at the top level of a script, there is no stack frame three levels above, so it fails. I'll make a PR to fix it in IPython - in the meantime, you can work around it by using ip.magic() instead of ip.run_line_magic().

  2. Log in to comment