2

Stated briefly: I would like to have a text file where I can smoothly switch among R, python and Julia. Of importance, I am looking for a way to run rather than just display code

I know it is possible to add python (and many other languages) to R markdown http://goo.gl/4w8XIb , but not sure I could add Julia. Also possible to use notebooks like Beaker http://beakernotebook.com/ with all three languages (and more) , but my issue with notebooks is that they are not nearly as fast to manipulate compared to what can be done with a text file in an editor environment (sublime, emacs, vim, atom ...). I know very little about notebooks, and the ones I know of are represented as json files, but manipulating a json file to write a report is all but user friendly.

I'm probably missing the obvious, but any other way to do this? thanks

  • this isn't an answer, but given the breadth of languages for which knitr engines *have* been implemented ([here](http://yihui.name/knitr/demo/engines/), it shouldn't be that hard. More specifically, look within https://github.com/yihui/knitr/blob/master/R/engine.R at `eng_interpreted` ... – Ben Bolker Jan 29 '16 at 01:42
  • thanks @BenBolker , the problem with R markdown is that a chunk with a python script cannot see objects from previous python chunks, and I'm afraid the same might happen with Julia. – Ricardo Pietrobon Jan 31 '16 at 15:18
  • 1
    haven't tested it just yet, but http://orgmode.org/worg/org-contrib/babel/ seems to be a possibility. Funny that I've been using org-mode for some time now, but had simply forgotten about Babel – Ricardo Pietrobon Jan 31 '16 at 15:20
  • 2
    Yihui Xie's `runr` package does provide a solution to that problem (I've tested that it works OK with Python3, but haven't used it extensively or tried to see what it would take to extend it to Julia ...) – Ben Bolker Jan 31 '16 at 15:28
  • plus 1 for org-mode, it does everything you want. – Ista Feb 01 '17 at 14:02

3 Answers3

2

I recently created an R package JuliaCall, and it can be used as julia engine in R Markdown document, see https://non-contradiction.github.io/JuliaCall/articles/JuliaCall_in_RMarkdown.html for an example.

Although JuliaCall is already on CRAN, this new feature is still in the development version on github. If you want to try it, use

devtools::install_github("Non-Contradiction/JuliaCall")

to install JuliaCall.

The feature includes

  1. Multiple julia chunks running by same julia session.
  2. Accessing R variables, functions inside julia code and vice versa.

The current limitation is that it only fully support html output.

Consistency
  • 2,884
  • 15
  • 23
1

With Restructured Text, there is good support for including code samples, where each code-block directive can include the relevant language.

.. code-block:: ruby

   Some Ruby code.

Markdown also supports mentioning the language with each code block, e.g.:

```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```

```python
s = "Python syntax highlighting"
print s
```

```
No language indicated, so no syntax highlighting. 
But let's throw in a <b>tag</b>.
```
taleinat
  • 8,441
  • 1
  • 30
  • 44
  • thanks @taleinat, but what I was looking for was a way to run rather than just display the code. So, for R markdow I can add scripts in R and python and it will display actual results. I've edited my question to clarify this – Ricardo Pietrobon Jan 29 '16 at 01:08
1

I think Beaker Notebook is actually a very good solution for your needs. It is a polyglot tool which will let you combine R, Python and Julia very well. There is a Vim editing mode which is not perfect, but still quite fast. There are shortcut keys for executing cells quickly, executing only selected lines, as well as jumping between cells. Beaker is also a permissively licensed open source project on GitHub with a very responsive maintainer, so you could also contribute any missing features directly as PRs.

ctrueden
  • 6,751
  • 3
  • 37
  • 69