0

This is my express server structure

--routes
 ----index.js
 ----graph.js
--scripts
 ----test.R
--server.js

I am trying to call R script from graph.js file as below

router.get('/test',function(req,res,next){
    var R = require("r-script");
    var out = R("./scripts/test.R")
              .data()
              .callSync();   
    res.send(out);
});

But I am getting the following error

TypeError: Cannot read property 'data' of undefined.

Any help is greatly appreciated. Thanks

4
  • Try R("../scripts/test.R") with an extra .. I think it's calling it relative to the graph.js, not server.js. Commented May 15, 2018 at 20:11
  • Yes, just tried still same error. Commented May 15, 2018 at 20:20
  • Looks like there is an issue with the repo itself. Take a look at joshkatz/r-script#19. You may need to install that particular pull request in order to deal with the issue until it is merged. Commented May 15, 2018 at 20:29
  • stackoverflow.com/questions/50093298/… Commented Jul 22, 2018 at 20:10

2 Answers 2

1

I believe it is being called relative to graph.js instead of server.js.

Try using R("../scripts/test.R") with an extra ..

Sign up to request clarification or add additional context in comments.

Comments

0

I'm facing this problem each time I install "r-script" but I found the solution a long time ago just there: https://github.com/joshkatz/r-script/pull/20/commits/1eb0c33628360957f0dd589b92e804fba15891d5.

Just replace return _.bindAll(obj, "data", "call", "callSync"); by:

  _.bindAll(obj, "data", "call", "callSync");
  return obj;

in the file: node_modules/r-script/index.js

Hope I helped you even if you asked more than 5 months ago.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.