2

Is it possible to execute an existing .R script file from within a Lua session? From this helpful page I know that you can access existing R-Sessions and extract objects from it. I also know that you can execute single commands with e. g.

local R = require "rclient"
local r = R.connect()
r "var <- c(1:10)"
local var = r.var

I have a pretty long R script that I don't want to run separately from outside Lua neither do I want to paste every line in the Lua script.

Is there a way to run the script from within Lua and, for example, pass Lua variables to the R script, and, afterwards, access the R objects?

oepix
  • 151
  • 2
  • 12
  • 1
    It sounds like you want quite a bit "for free" from that Lua module. It may be possible to read in a multi-line R script using Lua (preserving the newlines) and pass it in to the `(rcode, out = print)` function (as you do `r "var <- c(1:10)"`) and you should try that first. That module's API (scroll down to the bottom) has no obvious provisions to pass in Lua objects to R function calls. – hrbrmstr Oct 16 '18 at 13:05
  • 1
    One possible workaround (since you're OK with running Rserve in the background to support Lua<->R crosstalk/marshalling) is to convert your R script to an [R plumber API endpoint](https://github.com/trestletech/plumber) and make REST calls with Lua to it. – hrbrmstr Oct 16 '18 at 13:07
  • Thank you, I will definitely give it a try! Using "plumber" sounds like a promising alternative, too! – oepix Oct 16 '18 at 14:26

0 Answers0