elixir4r (WIP)
The package provides R interface to elixir
Installation
You can install the development version of elixir4r via:
devtools::install_github("enixam/elixir4r")
Example
First load the package
library(elixir4r)
Interfaces
Evaluate inline elixir code
ex_eval("
defmodule Test do
def main, do: IO.puts(:ok)
end
Test.main()
")
#> [1] "ok"
Run .exs
script
code <- "IO.write(['hello ', 'R'])"
tmp <- tempfile()
cat(code, file = tmp)
ex_run(tmp)
#> [1] "hello R"
R Markdown
After library
, elixir4r will register a custom knitr engine elixir
.
Insert an elixir
chunk
```{elixir}
{{year, month, day}, {hour, _, _}} = :calendar.local_time()
IO.puts("hello world from #{year}/#{month}/#{day} #{hour} o'clock")
```
This yields
#> hello world from 2022/1/5 18 o'clock
The last line of the code block gets automatically printed by
IO.inspect
m = %{name: "elixir", creator: "José Valim", status: :nice}
m
#> %{creator: "José Valim", name: "elixir", status: :nice}