I'm a developer learning elixir, I would like to be able to execute R functions from elixir. I heard it is possible with Rserve (
) and erlang gen_tcp. My first problem is how to send R calls (I'm not familiar with R myself by the way, but a collegue should help me with that). For example (elixir code):
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.3.0) - press Ctrl+C to exit (type h() ENTER for help)
{:ok, #Port<0.1200>}
iex(2)> :gen_tcp.send(socket, 'rnorm(100)')
:ok
iex(3)> {:ok, msg} = :gen_tcp.recv(socket, 0)
{:ok,
[82, 115, 114, 118, 48, 49, 48, 51, 81, 65, 80, 49, 13, 10, 13, 10, 45, 45, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 13, 10, 2, 0, 1, 66, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]}
iex(4)> :gen_tcp.close(socket)
:ok
{:ok, #Port<0.1253>}
iex(6)> :gen_tcp.send(socket, 'as.integer(20/10)')
:ok
iex(7)> {:ok, msg} = :gen_tcp.recv(socket, 0)
{:ok, 'Rsrv0103QAP1\r\n\r\n--------------\r\n'}
iex(8)> :gen_tcp.close(socket)
:ok