cscheid / rserve-js

Javascript implementation of the Rserve protocol
MIT License
47 stars 32 forks source link

null always passed to r.eval's callback #16

Closed ghost closed 10 years ago

ghost commented 10 years ago

I'm new to rserve-js, and just tried to go through the quick tour for a start. Everything runs fine, until I issue: r.eval('rnorm(10)', function(a) { console.log(a); })

Instead of something similar to the JSON object shown in the README, I always get null... Even when I try some trivial R expression, such as '1'.

Does someone have a clue on my problem? I run Ubuntu 12.04 (64bit), R 3.0.3, and node v0.11.11. I tried several older versions of node, with the same result.

cscheid commented 10 years ago

Ah, this is a bug in the documentation, I'm sorry. I'll fix it soon, but the problem is we changed the callback style to be compatible with the one used by node.js, and so your callbacks are passed the error object (if any) as the first parameter.

r.eval('rnorm(10)', function(err, value) { if (err !== null)

console.log(a); })

I completely agree that this is non-intuitive, but it seems to be the default that the javascript ecosystem has picked.

ghost commented 10 years ago

Thanks for the quick answer! Actually there's still a mistake in your snippet, one should read:

r.eval('rnorm(10)', function(err, value) { if (err === null) console.log(value); })

And works fine this way! And this explains why I kept logging null: the operation was successful ^^

BTW, there is a typo in the quick tour: one should read "r_files/start_no_ocap" (without an "s")

Thanks again!

cscheid commented 10 years ago

Thank you for your patience with bad documentation; I'm happy it worked for you!

cscheid commented 10 years ago

Ok, I made the changes to README.md. Thank you very much for your report!