Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATS: Execute script by node text, inject data from node and return json to node #16

Open
gabolera opened this issue Sep 22, 2023 · 1 comment

Comments

@gabolera
Copy link

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.

@gabolera
Copy link
Author

@FabrizioSandri Hello dear, I would like your opinion on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant