Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using magic commands outside of Interactive Shell in IPython

Is there a way to use "magic commands" from IPython from an outside file? For example if I have a file, "rcode.py" with the code:

%load_ext rmagic
%R a=c(1,2,3);b=c(2,3,4);print(summary(lm(a~b)))

This gives me a SyntaxError for the first line when I run it using ipython rcode.py in the command line. However when I type these lines straight into the interactive shell with ipython it runs fine. Is this because you only do magic in the interactive shell?

Thanks!

like image 350
Dan Avatar asked Aug 31 '12 16:08

Dan


1 Answers

If you name your file with a .ipy extension, ipython will parse it properly. You can simply make a symlink if you want:

$ ln -s rcode.py rcode.ipy
$ ipython rcode.ipy
like image 68
jdi Avatar answered Nov 01 '22 09:11

jdi