3

How can I convert the jupyter R magics like %%R or %Rpush or %Rpull or the execution of an R function into a regular python script?

6
  • 1
    Do you want an automatic conversion? One possibility is to put all the %%R cells into a script and then use subprocess to call the script. This question suggests using rpy2 with r.source("script.R") Commented Oct 24, 2016 at 22:13
  • Automatic conversion sounds great! Commented Oct 25, 2016 at 5:46
  • You mean like: stackoverflow.com/questions/6434569/… process = subprocess.Popen(['R', '--vanilla', '--args', '\\%s_DM_Instances_R.csv\\' % output_filename, '<', '/home/kevin/AV-labels/Results/R/hierarchical_clustering.R'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True) process.communicate()#[0] is stdout but how whould %Rpush / %Rpull work? Commented Oct 25, 2016 at 5:48
  • In Jupyter I already have a single %%R function which takes the arguments via %Rpush and I get the result via %Rpull I just would like to put it into a "normal" python script without the jupyter magics dependencies. Commented Oct 25, 2016 at 5:49
  • And here r-bloggers.com/… system2 is used for the subprocess. Is this "required"? Commented Oct 25, 2016 at 5:53

1 Answer 1

0

The answer is partly in the comments above: http://rpy2.readthedocs.io/en/version_2.8.x/introduction.html#creating-rpy2-vectors here is a nice and longer explanation This is the solution to the last mentioned problem of implementing a %Rpush robjects.IntVector([1, 2, 3])

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.