r-integration
r-integration copied to clipboard
FEATS: Execute script by node text, inject data from node and return json to node
I have different needs for this library
Execute script from node text
Create a method inside nodejs for write all script and send to R for executation
Example
R.executeRawScript(`
if(!require(ltm)) install.packages("ltm", repos = "http://cran.us.r-project.org")
library("ltm")
options(max.print=1000000)
options(scipen = 999, digits = 4)
# more script...
`)
Inject values in script with nodejs
Example
R.executeRawScript(`
if(!require(ltm)) install.packages("ltm", repos = "http://cran.us.r-project.org")
library("ltm")
options(max.print=1000000)
options(scipen = 999, digits = 4)
data = read.csv(file = 'NODE_TEXT(<FILENAME>)', header = T, fileEncoding = "UTF-8-BOM", sep = ";", na.strings = '..')`,
{
FILENAME: 'data.csv'
}
)
filename is being injected into the R script for execution
After execute script return json to node
const results = R.executeRawScript(`
if(!require(ltm)) install.packages("ltm", repos = "http://cran.us.r-project.org")
library("ltm")
options(scipen = 999, digits = 4)
data = read.csv(file = 'data.csv', header = T, fileEncoding = "UTF-8-BOM", sep = ";", na.strings = '..')
NODE_RETURN(data)`
)
console.log(results)
returning
[
["John", "Doe"],
["Alex", "Rosa"],
]
NODE_RETURN is a function has a replaced by node before execute and back to user end data
Custom types for integration
Type | Function |
---|---|
NODE_TEXT | Inject in script any text |
NODE_ARRAY | Inject a data array into the script |
NODE_RETURN | Return the data table in json format for nodejs |
I don't know if I was very clear in the issue, I'm getting for a fork to make the necessary modifications and present the operation as soon as possible, The reazon these question is be a real case, and I'm having the difficulties reported.
@FabrizioSandri Hello dear, I would like your opinion on this