From: Kyle Meyer <kyle@kyleam.com>
To: Jack Kamm <jackkamm@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [RFC] ob-reticulate: R+Python interface from Babel
Date: Sat, 29 Aug 2020 09:23:57 -0400 [thread overview]
Message-ID: <87k0xhshzm.fsf@kyleam.com> (raw)
In-Reply-To: <875z98gj4f.fsf@gmail.com>
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 :)
next prev parent reply other threads:[~2020-08-29 13:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 15:26 [RFC] ob-reticulate: R+Python interface from Babel Jack Kamm
2020-08-25 23:34 ` Kyle Andrews
2020-08-29 13:23 ` Kyle Meyer [this message]
2020-09-04 7:14 ` Bastien
2020-10-12 4:15 ` Jack Kamm
2021-02-27 14:15 ` Jack Kamm
2021-02-27 17:24 ` Jeremie Juste
2021-03-02 23:52 ` Jack Kamm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k0xhshzm.fsf@kyleam.com \
--to=kyle@kyleam.com \
--cc=emacs-orgmode@gnu.org \
--cc=jackkamm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).