NOTE: All instructions in capital letters indicate code that you should fill in with the appropriate information.
reticulate package (do not include this code).reticulate library.library(reticulate)
py_config() to find the python versions you have installed on your machine.python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.16 (default, Oct 17 2019, 17:14:30) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s
numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
numpy_version: 1.8.0
python versions found:
/usr/bin/python
/usr/bin/python3
/usr/local/bin/python3
/Users/buchanan/anaconda3/bin/python
python on the top line is the one you want to use, you are all done./Users/buchanan/...) and tell R to talk to that python instead.use_python("PATH", required = TRUE).use_python() after running py_config(). You will get an error message:ERROR: The requested version of Python
('/Users/buchanan/anaconda3/bin/python') cannot be used, as
another version of Python ('/usr/bin/python') has already
been initialized. Please restart the R session if you need
to attach reticulate to a different version of Python.
Error in use_python("/Users/buchanan/anaconda3/bin/python", required = TRUE) :
failed to initialize requested version of Python
use_python() code.py_config() and use_python() in the same markdown. Once you know where your path is, just use use_python().py_config()
## python: D:\Development\Anaconda\envs\r-reticulate\python.exe
## libpython: D:/Development/Anaconda/envs/r-reticulate/python36.dll
## pythonhome: D:\Development\Anaconda\envs\r-reticulate
## version: 3.6.7 (default, Dec 6 2019, 07:03:06) [MSC v.1900 64 bit (AMD64)]
## Architecture: 64bit
## numpy: D:\Development\Anaconda\envs\r-reticulate\lib\site-packages\numpy
## numpy_version: 1.17.3
##
## python versions found:
## D:\Development\Anaconda\envs\r-reticulate\python.exe
## D:\Development\Anaconda\python.exe
data(rock) to load it.head() function to print out the first six rows of the dataset.data(rock)
head(rock,6)
## area peri shape perm
## 1 4990 2791.90 0.0903296 6.3
## 2 7002 3892.60 0.1486220 6.3
## 3 7558 3930.66 0.1833120 6.3
## 4 7352 3869.32 0.1170630 6.3
## 5 7943 3948.54 0.1224170 17.1
## 6 7979 4010.15 0.1670450 17.1
numpy, nltk, spacy, seaborn and pandas for starters.py_module_available("PACKAGE").py_module_available("numpy")
## [1] TRUE
py_module_available("nltk")
## [1] TRUE
py_module_available("seaborn")
## [1] TRUE
py_module_available("spacy")
## [1] TRUE
py_module_available("numpy")
## [1] TRUE
FALSE, then install them using py_install("PACKAGE").##r chunk
#if they are all TRUE, leave this blank
seaborn library, it has several sample datasets. You load python packages by using import PACKAGE.dots dataset by doing: VARNAME = PACKAGENAME.load_dataset("DATASETNAME")..head() function: VARNAME.head().##python chunk
import seaborn
VARNAME = seaborn.load_dataset("dots")
VARNAME.head()
## align choice time coherence firing_rate
## 0 dots T1 -80 0.0 33.189967
## 1 dots T1 -80 3.2 31.691726
## 2 dots T1 -80 6.4 34.279840
## 3 dots T1 -80 12.8 32.631874
## 4 dots T1 -80 25.6 35.060487
QUESTION: Look in your environment window. What do you see?
py$VARNAME.DATAFRAME$COLUMN. Try to print out the time column from your dots variable (whatever you named it above).py$VARNAME$time
## [1] -80 -80 -80 -80 -80 -80 -60 -60 -60 -60 -60 -60 -40 -40 -40
## [16] -40 -40 -40 -20 -20 -20 -20 -20 -20 0 0 0 0 0 0
## [31] 20 20 20 20 20 20 40 40 40 40 40 40 60 60 60
## [46] 60 60 60 80 80 80 80 80 80 100 100 100 100 100 100
## [61] 120 120 120 120 120 120 140 140 140 140 140 140 160 160 160
## [76] 160 160 160 180 180 180 180 180 180 200 200 200 200 200 200
## [91] 220 220 220 220 220 220 240 240 240 240 240 240 260 260 260
## [106] 260 260 260 280 280 280 280 280 280 300 300 300 300 300 320
## [121] 320 320 320 320 340 340 340 340 340 360 360 360 360 360 380
## [136] 380 380 380 380 400 400 400 400 400 420 420 420 420 420 440
## [151] 440 440 440 460 460 460 460 480 480 480 480 500 500 500 500
## [166] 520 520 520 520 540 540 540 540 560 560 560 560 580 580 580
## [181] 600 600 600 620 620 620 640 640 660 660 680 680 700 720 -80
## [196] -80 -80 -80 -80 -80 -60 -60 -60 -60 -60 -60 -40 -40 -40 -40
## [211] -40 -40 -20 -20 -20 -20 -20 -20 0 0 0 0 0 0 20
## [226] 20 20 20 20 20 40 40 40 40 40 40 60 60 60 60
## [241] 60 60 80 80 80 80 80 80 100 100 100 100 100 100 120
## [256] 120 120 120 120 120 140 140 140 140 140 140 160 160 160 160
## [271] 160 160 180 180 180 180 180 180 200 200 200 200 200 200 220
## [286] 220 220 220 220 220 240 240 240 240 240 240 260 260 260 260
## [301] 260 260 280 280 280 280 280 280 300 300 300 300 300 300 320
## [316] 320 320 320 320 320 340 340 340 340 340 360 360 360 360 360
## [331] 380 380 380 380 380 400 400 400 400 400 420 420 420 420 420
## [346] 440 440 440 440 440 460 460 460 460 480 480 480 480 500 500
## [361] 500 500 520 520 520 520 540 540 540 540 560 560 560 560 580
## [376] 580 580 600 600 600 620 620 620 640 640 640 660 660 680 680
## [391] 700 700 720 720 -600 -580 -560 -560 -540 -540 -520 -520 -500 -500 -500
## [406] -480 -480 -480 -460 -460 -460 -440 -440 -440 -440 -420 -420 -420 -420 -400
## [421] -400 -400 -400 -380 -380 -380 -380 -360 -360 -360 -360 -340 -340 -340 -340
## [436] -320 -320 -320 -320 -300 -300 -300 -300 -300 -280 -280 -280 -280 -280 -260
## [451] -260 -260 -260 -260 -240 -240 -240 -240 -240 -220 -220 -220 -220 -220 -200
## [466] -200 -200 -200 -200 -180 -180 -180 -180 -180 -160 -160 -160 -160 -160 -160
## [481] -140 -140 -140 -140 -140 -140 -120 -120 -120 -120 -120 -120 -100 -100 -100
## [496] -100 -100 -100 -80 -80 -80 -80 -80 -80 -60 -60 -60 -60 -60 -60
## [511] -40 -40 -40 -40 -40 -40 -20 -20 -20 -20 -20 -20 0 0 0
## [526] 0 0 0 20 20 20 20 20 20 40 40 40 40 40 40
## [541] 60 60 60 60 60 60 80 80 80 80 80 80 100 100 100
## [556] 100 100 100 120 120 120 120 120 120 140 140 140 140 140 140
## [571] 160 160 160 160 160 160 180 180 180 180 180 180 200 200 200
## [586] 200 200 200 220 220 220 220 220 220 240 240 240 240 240 240
## [601] 260 260 260 260 260 260 280 280 280 280 280 280 300 300 300
## [616] 300 300 300 -600 -600 -580 -580 -560 -560 -540 -540 -520 -520 -520 -500
## [631] -500 -500 -480 -480 -480 -460 -460 -460 -440 -440 -440 -440 -420 -420 -420
## [646] -420 -400 -400 -400 -400 -380 -380 -380 -380 -360 -360 -360 -360 -340 -340
## [661] -340 -340 -320 -320 -320 -320 -320 -300 -300 -300 -300 -300 -280 -280 -280
## [676] -280 -280 -260 -260 -260 -260 -260 -240 -240 -240 -240 -240 -220 -220 -220
## [691] -220 -220 -200 -200 -200 -200 -200 -200 -180 -180 -180 -180 -180 -180 -160
## [706] -160 -160 -160 -160 -160 -140 -140 -140 -140 -140 -140 -120 -120 -120 -120
## [721] -120 -120 -100 -100 -100 -100 -100 -100 -80 -80 -80 -80 -80 -80 -60
## [736] -60 -60 -60 -60 -60 -40 -40 -40 -40 -40 -40 -20 -20 -20 -20
## [751] -20 -20 0 0 0 0 0 0 20 20 20 20 20 20 40
## [766] 40 40 40 40 40 60 60 60 60 60 60 80 80 80 80
## [781] 80 80 100 100 100 100 100 100 120 120 120 120 120 120 140
## [796] 140 140 140 140 140 160 160 160 160 160 160 180 180 180 180
## [811] 180 180 200 200 200 200 200 200 220 220 220 220 220 220 240
## [826] 240 240 240 240 240 260 260 260 260 260 260 280 280 280 280
## [841] 280 280 300 300 300 300 300 300
$, we use . like this: r.VARNAME.DATAFRAME["COLUMNNAME"]. Try printing out the shape column in the rock dataset.##python chunk
r.rock["shape"]
## 0 0.090330
## 1 0.148622
## 2 0.183312
## 3 0.117063
## 4 0.122417
## 5 0.167045
## 6 0.189651
## 7 0.164127
## 8 0.203654
## 9 0.162394
## 10 0.150944
## 11 0.148141
## 12 0.228595
## 13 0.231623
## 14 0.172567
## 15 0.153481
## 16 0.204314
## 17 0.262727
## 18 0.200071
## 19 0.144810
## 20 0.113852
## 21 0.291029
## 22 0.240077
## 23 0.161865
## 24 0.280887
## 25 0.179455
## 26 0.191802
## 27 0.133083
## 28 0.225214
## 29 0.341273
## 30 0.311646
## 31 0.276016
## 32 0.197653
## 33 0.326635
## 34 0.154192
## 35 0.276016
## 36 0.176969
## 37 0.438712
## 38 0.163586
## 39 0.253832
## 40 0.328641
## 41 0.230081
## 42 0.464125
## 43 0.420477
## 44 0.200744
## 45 0.262651
## 46 0.182453
## 47 0.200447
## Name: shape, dtype: float64