Skip to content
Advertisement

%% Cell magic tag not working in Jupyter notebook?

I’m new to Jupyter notebook and I’m trying to set one up with Python and R, using rpy2. I have the line

JavaScript

which gives me the error SyntaxError: invalid syntax

However when I use just one %, such as

JavaScript

this works fine. How can I fix this issue? I am using Python 2.7.

Advertisement

Answer

% prefix is for a line magic, whereas %% prefix is for a cell magic.

JavaScript

whereas:

JavaScript

I don’t have R installed, but I think you may have wanted to call a bash command on R; in that case, use ! to call the command:

JavaScript

for instance, if I type !python -i, I get info about my current python environment:

JavaScript
Advertisement