2

I'm using R markdown and trying to access to variables in the python chunk from r chunk, but the results return NULL in the r chunk. I tried to follow the instruction here. My code as follow, what is the issue here?

```{r setup}
library(reticulate)
use_python("/usr/local/bin/python")
```

```{python}
import pandas as pd
Dict = {'x1': [1,2,3], 'x2': [4,5,6], 'x3': [7,8,9] }
my_df2 = pd.DataFrame(Dict)
print(my_df2) # works fine
``` 

```{r}
print(py$my_df2) # return NULL
```

Thanks!

Lumos
  • 1,303
  • 2
  • 17
  • 32
  • Your code (in the form I edited it) produces an error for me since `pd` is unknown. When I add `import pandas as pd` (and remove `use_python(...)` since I have no `/usr/local/bin/python`), the code works without problems in RStudio. – Ralf Stubner Oct 31 '19 at 21:30
  • @RalfStubner thx for replying. I also tried to remove use_python(), also specified import pandas as pd, still NULL in my R chunk. Something wrong with my Rstudio? – Lumos Nov 05 '19 at 04:36
  • Are you able to access simpler variables from R, say a double? – Ralf Stubner Nov 05 '19 at 12:23

0 Answers0