2

When working in an R Notebook:

If I define a variable in an R chunk it is added to the global environment and is accessible to all other R chunks.

```{r}
a = 1 + 4
a
```

However, I haven't been able to pass the variable into a Python chunk or to access R's Global Environment from Python, even using rpy2.

```{python, engine.path="/anaconda/bin/python"}
import rpy2.robjects as robjects
a = robjects.r['a']
print(a[0])
```

Is there a way to do this? If not, I don't see the point of using a non-R language in an R Notebook. I could use Magics in Jupiter Notebook but that doesn't seem as easy.

  • 1
    Magics are easy and they are made for this kind of things, you should definetly go for that. – alec_djinn May 30 '17 at 20:57
  • I could be completely wrong (hence leaving this as a comment), but I remember a presentation where they used `feather` for this. Not sure there's a way to pass pointers between the two languages, or if the languages would understand each others' pointers anyway... – MichaelChirico May 30 '17 at 21:00
  • There's an extremely literate notebook that shows how to interface Python and R in a Jupyter notebook, using magics. https://github.com/eclarson/DataMiningNotebooks/blob/master/01.%20PandasAndR.ipynb. Disclaimer: the author is a former professor of mine. – Arya McCarthy May 30 '17 at 21:01
  • @alec_djinn I'll just have to buckle down and learn it, haha. Thanks. – MadDataScientist May 31 '17 at 00:03
  • @MichaelChirico I'll look more into that. Thanks! – MadDataScientist May 31 '17 at 00:03
  • @AryaMcCarthy Thanks for the reference! That looks like it will help a lot. – MadDataScientist May 31 '17 at 00:04

0 Answers0