Jack Kamm writes: > Hi all, > > Reticulate is an R package for interfacing between R and Python. It > allows accessing objects in a Python session from R and vice > versa. See https://rstudio.github.io/reticulate/ for more info about > it. > > I've written a small patch for using reticulate from org-babel. It > allows creating a source block of lang "reticulate", which behaves as > Python for font highlighting and editing, but is executed in an R > session via reticulate.
Neat, thanks for sharing. > I'm wondering whether this should go into org-mode, or whether to > package this separately. I'm also curious whether this would be useful > to anyone here. Any feedback is appreciated. It'd be good to hear from others, but in my view this would be fine to add to Org proper. I will say that in general new Babel libraries make me nervous. My impression is that Babel brings in a good number of bug reports, and a new library is adding surface to that area [*] while not necessarily adding eyes and hands. Of course that worry doesn't apply here, as you're already taking care of ob-python. [*] And that surface can be quite challenging to deal with because it is not just Elisp code; it brings in a whole outside language that other developers may have no clue about. > +;;; Code: > + > +(require 'ob-R) > +(require 'ob-python) > + > +(defalias 'org-babel-edit-prep:reticulate 'org-babel-edit-prep:R) > + > +(defun org-babel-execute:reticulate (body params) > + (let* ((tmp-src-file (org-babel-temp-file "reticulate-")) > + (result-type (cdr (assq :result-type params)))) > + (with-temp-file tmp-src-file (insert body)) > + (org-babel-execute:R > + (format (concat "reticulate::py_run_string(\"%s\")" > + (when (equal result-type 'value) " > +reticulate::py$`__org_babel_python_final`")) > + (format org-babel-python--eval-ast > + (org-babel-process-file-name > + tmp-src-file 'noquote))) > + params))) > + > +(provide 'ob-reticulate) Well, that's pleasantly few lines of code :)