[NTG-context] Can anyone connect context to R or python?

Aditya Mahajan adityam at umich.edu
Sat Oct 6 19:06:18 CEST 2018


On Sat, 6 Oct 2018, Kelley, Claire wrote:

> Again thank you everyone for their incredibly helpful advice and responsiveness!
>
> The work flow I am envisioning is:
>
> 1) Use R to read in a csv file, filter according to some rules and then use propensity score matching (based on r packages) to create a model.
> 2) The final data output is a table with standardize coefficients and mean values.
> 3) This final data output is then used to create a table using Context/ Tikz to create the very specific format that I need for the final report.

Is the final post-processed data a table that can be saved to a CSV file? 
If so, the simplest solution will be to write R code (inside a \startR ... 
\stopR environment) that does the post-processing and saves the data as a 
CSV file.

Both ConTeXt and TikZ can easily read CSV table and format as desired.

---

I also want to take this opportunity to express my views on intefacing 
with external programs. The file based interaction provided by the filter 
module is okay for small projects but it is not ideal. Slightly better is 
to use pipes (popen to a REPL) or use FFI 
(e.g https://adityam.github.io/context-blog/post/interfacing-with-julia), 
but neither of these is easy to implement and needs to be done on a 
per-language basis. Henri Menke had a Tugboat article on this as well.

In my opinion, a better long-term option is to write a jupyter client in 
lua that can be called by context. Then we can easily interface with all 
languages that provide a jupyter kernel 
(https://github.com/jupyter/jupyter/wiki/Jupyter-kernels).

The interface of a jupter-client is available here
https://jupyter-client.readthedocs.io/en/stable/index.html. It seems 
relatively straight forward (send a JSON message and receive a JSON 
message). Translating the JSON messages to ConTeXt should also be easy. 
Is there anyone who wants to play around trying to implement this?

Aditya


More information about the ntg-context mailing list