kmace kmace - 1 year ago 203
Python Question

Passing data from python chunk to R environment in Rnotebook

I've got some data given to me in a python shelve file, I want to pass it to R for plotting. my code to extract it looks like this:

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

```{python}
import numpy as np
from numpy import ma, array
import shelve

MODEL = "May2016"
d = shelve.open('fits_shelve_' + MODEL)
hilldata = d['hilldata']
allchi = d['allchi']
aa = d['aa']
rr = d['rr']
names = d['names']
weight = d['weight']
weightc = d['weightc']
dl = d['dl']
vi = d['activatorM']
activatorM = d['activatorM']
activatorR = d['activatorR']
d.close()

```


I would now like to pass these object to R. Is there a way to do this in Rnotebook? I know something similar is possible with SQL chunks.

Answer Source

I think for python/R interaction you'll have to save the data to the file system in one chunk and read it back in another.

http://rmarkdown.rstudio.com/authoring_knitr_engines.html#python

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download