4

I want to accomplish a loop over R code within an IPython notebook. What is the best way to do this?

    l = []
    for i in range(10):
        # execute R script
        %%R -i i -o result   #some arbitrary R code
        # and use the output
        l.append(result)

Can this be done inside a notebook (Looping over next cell)?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Bjoern
  • 171
  • 1
  • 11

1 Answers1

2

Have you looked into rmagic and rpy2 module?

If you have R scripts, then you can call them and assign their output to a variable using the shell command notation:

     var=!R_script arguments....

The above does not need you need you to install rpy2 since ! shell command execution is basic in ipython. You can pass values of variables from ipython notebook by using $var in the arg list.

nom-mon-ir
  • 3,748
  • 8
  • 26
  • 42