Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 1.69 KB

Readme.org

File metadata and controls

67 lines (50 loc) · 1.69 KB

ob-reticulate

org-babel support for the reticulate interface between R and Python.

Getting started

ob-reticulate is available from MELPA. It requires Org 9.4 or higher.

To get started, load ob-reticulate, then enable it by activating ob-reticulate-mode:

(require 'ob-reticulate)
(ob-reticulate-mode)

Usage

Simply pass an interactive R buffer’s name as the :session header argument to an ob-python block. The Python block will then be executed via reticulate in the R session.

You’ll need to first load reticulate in the R session by calling library(reticulate).

For example:

#+begin_src R :session *R:ob-reticulate* :results output
  library(reticulate)
#+end_src

#+RESULTS:

#+begin_src python :session *R:ob-reticulate* :colnames yes
  import pandas as pd
  df = pd.DataFrame({"X":[1,2,3], "Y":["a","b","c"]})
  df
#+end_src

#+RESULTS:
| X | Y |
|---+---|
| 1 | a |
| 2 | b |
| 3 | c |

#+begin_src R :session *R:ob-reticulate* :results output
  summary(py$df)
#+end_src

#+RESULTS:
:        X            Y            
:  Min.   :1.0   Length:3          
:  1st Qu.:1.5   Class :character  
:  Median :2.0   Mode  :character  
:  Mean   :2.0                     
:  3rd Qu.:2.5                     
:  Max.   :3.0

Note on header arguments

Reticulate blocks use header arguments for ob-R instead of ob-python. For example, the :colnames and :rownames headers, which are available in ob-R but not ob-python, can be used with blocks executed by reticulate.