How to let elixir /phoenix communicate async with programs in R

196 views
Skip to first unread message

Stefan Houtzager

unread,
Jul 19, 2016, 5:01:53 AM7/19/16
to elixir-lang-talk
Asked this question also on elixirforum.com (see below). Anyone with R experience in this group that can help? As a first test I would like to call this R program async from elixir, as a test:

divide <- function(x){
  out <- as.integer(x/10)
  Sys.sleep(10)
  return(out)
} 

How can I do this, do you have some code examples? Maybe RServe (https://rforge.net/Rserve/) could be handy to use? I know nothing of R yet, but would like to call R programs built by a collegue.

What would be the alternatives, could porcelain be a good choice?

If there is a good TCP or Pipe implementation that you could use in R then that would be a great way, or Porcelain if you want the Elixir system to manage the R execution as well.

OvermindDL1

unread,
Jul 19, 2016, 10:19:34 AM7/19/16
to elixir-lang-talk
RServe looks like it would work, however how does your collegues program want to be called?  Via a shell command?  TCP?  Etc...?

Stefan Houtzager

unread,
Jul 19, 2016, 1:19:44 PM7/19/16
to elixir-l...@googlegroups.com
I have to await the answer of my collegue (just mailed him). In the meantime I'm almostly sure we are free in our choice. What would be the options? I think it might be handy in the end if we could execute R-tasks simultaneous, like elixir tasks with a yield_many (Task module) to get the results. 

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/f5c66f7c-0190-41c8-9cfa-a2df4c8fe7b4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

www.linkedin.com/in/stefanhoutzager

OvermindDL1

unread,
Jul 19, 2016, 5:53:54 PM7/19/16
to elixir-lang-talk
Elixir/Erlang can support almost any style, but it is definitely a more natural fit for something TCP-based, however if you need to transfer massive amounts of data (megs or more at a time) then a raw open 'Port' would probably be the fastest.

If, for some reason, you needed absolute speed, you could make a C embedded Port (or unsafely, but faster, a C nif) to interact with it, but that is way way way overkill for most purposes.

Stefan Houtzager

unread,
Jul 20, 2016, 8:04:08 AM7/20/16
to elixir-l...@googlegroups.com
Thanks, TCP-based would be fine, I'll see what I can find out. I haven't worked with TCP servers before, would http://andrealeopardi.com/posts/handling-tcp-connections-in-elixir/ be a good intro?


For more options, visit https://groups.google.com/d/optout.

OvermindDL1

unread,
Jul 20, 2016, 9:58:44 AM7/20/16
to elixir-lang-talk
It looks decent, although very low level.  I'd say learn that article to see how it works, then promptly use another library, like I just found this on hex.pm:  https://hex.pm/packages/teacup  :-)

I also found this, but its had no updates in a half-year, so it may be stable or may be old?  https://hex.pm/packages/gen_listener_tcp

OvermindDL1

unread,
Jul 20, 2016, 10:00:05 AM7/20/16
to elixir-lang-talk
Though, to be honest, even raw TCP in Elixir is dead-simple.
Reply all
Reply to author
Forward
0 new messages