I try to use Python in RStudio. Using Python modules by R works fine.
```{r}
library(reticulate)
py_install("pandas")
pd = import("pandas", convert = FALSE)
r_mtcars = pd$DataFrame(mtcars)
r_mtcars$describe()
```
mpg cyl disp ... am gear carb
count 32.000000 32.000000 32.000000 ... 32.000000 32.000000 32.0000
mean 20.090625 6.187500 230.721875 ... 0.406250 3.687500 2.8125
std 6.026948 1.785922 123.938694 ... 0.498991 0.737804 1.6152
min 10.400000 4.000000 71.100000 ... 0.000000 3.000000 1.0000
25% 15.425000 4.000000 120.825000 ... 0.000000 3.000000 2.0000
50% 19.200000 6.000000 196.300000 ... 0.000000 4.000000 2.0000
75% 22.800000 8.000000 326.000000 ... 1.000000 4.000000 4.0000
max 33.900000 8.000000 472.000000 ... 1.000000 5.000000 8.0000
[8 rows x 11 columns]
However, if I try to use Python modules by Python I get an error.
```{python}
import pandas
py_mtcars = r.mtcars
```
Traceback (most recent call last):
File "...Temp\RtmpUzhmLU\chunk-code2a0865ca6eb6.txt", line 4, in <module>
py_mtcars = r.mtcars
NameError: name 'r' is not defined
r.
is normally used to tell Python that mtcars
is a R source.
The other way is also not possible i.e. access Python data by R.
```{python}
import pandas
mtcars = pandas.read_csv("../PyR/mtcars.csv")
```
```{r}
py$mtcars
```
Error in py_get_attr_impl(x, name, silent) : AttributeError: module '__main__' has no attribute 'mtcars'
Information on Python version:
py_config()
python: ~\Anaconda3\envs\r-reticulate\python.exe
libpython: ~/Anaconda3/envs/r-reticulate/python36.dll
pythonhome: ~\ANACON~1\envs\R-RETI~1
version: 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: ~\ANACON~1\envs\R-RETI~1\lib\site-packages\numpy
numpy_version: 1.14.3
pandas: ~\ANACON~1\envs\R-RETI~1\lib\site-packages\pandas\__init__.p
EDIT:
library(reticulate); devtools::session_info()
- Session info --------------------------------------------------------------------------------------------
setting value
version R version 3.5.2 (2018-12-20)
os Windows >= 8 x64
system x86_64, mingw32
ui RStudio
language (EN)
collate German_Germany.1252
ctype German_Germany.1252
tz Europe/Berlin
date 2019-04-19
- Packages ------------------------------------------------------------------------------------------------
package * version date lib source
assertthat 0.2.0 2017-04-11 [1] CRAN (R 3.5.0)
backports 1.1.3 2018-12-14 [1] CRAN (R 3.5.2)
callr 3.1.1 2018-12-21 [1] CRAN (R 3.5.2)
cli 1.0.1 2018-09-25 [1] CRAN (R 3.5.2)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.0)
desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.2)
devtools 2.0.1 2018-10-26 [1] CRAN (R 3.5.2)
digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.2)
fs 1.2.6 2018-08-23 [1] CRAN (R 3.5.2)
glue 1.3.0.9000 2019-01-28 [1] Github (tidyverse/glue@8188cea)
jsonlite 1.6 2018-12-07 [1] CRAN (R 3.5.2)
lattice 0.20-38 2018-11-04 [2] CRAN (R 3.5.2)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.0)
Matrix 1.2-15 2018-11-01 [2] CRAN (R 3.5.2)
memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.0)
pkgbuild 1.0.2 2018-10-16 [1] CRAN (R 3.5.2)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.2)
prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.1)
processx 3.2.1 2018-12-05 [1] CRAN (R 3.5.2)
ps 1.3.0 2018-12-21 [1] CRAN (R 3.5.2)
R6 2.3.0 2018-10-04 [1] CRAN (R 3.5.2)
Rcpp 1.0.0 2018-11-07 [1] CRAN (R 3.5.2)
remotes 2.0.2 2018-10-30 [1] CRAN (R 3.5.2)
reticulate * 1.10.0.9003 2019-01-28 [1] Github (rstudio/reticulate@6a60dad)
rlang 0.3.1 2019-01-08 [1] CRAN (R 3.5.2)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.0)
rstudioapi 0.9.0 2019-01-09 [1] CRAN (R 3.5.2)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.2)
testthat 2.0.1 2018-10-13 [1] CRAN (R 3.5.2)
usethis 1.4.0 2018-08-14 [1] CRAN (R 3.5.2)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.0)
yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1)
[1] ~/Documents/R/win-library/3.5
[2] C:/Program Files/R/R-3.5.2/library
StackOverflow says I have to much code in my post. So, nice Eastern and thanks for your help. I hope we get it done.