Re: [RFC] ob-reticulate: R+Python interface from Babel

2020-10-11 Thread Jack Kamm
Hi all,

I've put ob-reticulate.el on github so it can be more easily used:
https://github.com/jackkamm/ob-reticulate

I plan to submit it to MELPA or GNU ELPA over the coming weeks as well.

Cheers,
Jack



Re: [RFC] ob-reticulate: R+Python interface from Babel

2020-09-04 Thread Bastien
Hi Jack and Kyle,

Kyle Meyer  writes:

>> 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 think this would be a good addition to Org ecosystem (thanks Jack!)
but I also feel like we need to tidy things up a bit wrt Org Babel and
have stricter rules for library inclusion.

I will bring this as a separate discussion/proposal once 9.4 is out.

Thanks!

-- 
 Bastien



Re: [RFC] ob-reticulate: R+Python interface from Babel

2020-08-29 Thread Kyle Meyer
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 :)



Re: [RFC] ob-reticulate: R+Python interface from Babel

2020-08-25 Thread Kyle Andrews
Hi Jack,

As a frequent reticulate user I am very excited to see this patch. I hope
others feel the same and it gets included into org mode as I cannot wait to
use it.

Best Regards,
Kyle

On Mon, Aug 24, 2020, 11:28 Jack Kamm  wrote:

> 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.
>
> 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.
>
> The main advantage of reticulate is being able to access Python objects
> directly from R and vice versa, without having to write them to a separate
> file or pass them through the ":var" header argument. For example, we could
> do the following:
>
> #+begin_src reticulate :session
>   import pandas as pd
>
>   fib = [0, 1]
>   for _ in range(10):
>   fib.append(fib[-1] + fib[-2])
>
>   df = pd.DataFrame({
>   "i": list(range(len(fib))),
>   "F_i": fib
>   })
> #+end_src
>
> #+begin_src R :session :results graphics value file :file fig.png
>   library(reticulate)
>   with(py$df, plot(i, F_i))
> #+end_src
>
> Reticulate source blocks support both "value" and "output" results, and
> even supports graphics with matplotlib. It's primarily intended to be used
> in sessions, and the ":session" header argument should match between
> reticulate and R source blocks.
>
> Cheers,
> Jack
>
>