libRmath.js: rnorm crashes when generating a single sample
This is using version 1.0.76 installed from npm today. When getting a single sample from the normal distribution, an error is thrown:
const libR = require('lib-r-math.js');
libR.Normal().rnorm();
TypeError: r_func_1.seq(...)(...)(...).map is not a function
at Object.rnorm (./node_modules/lib-r-math.js/dist/lib/libR.js:3905:41)
at Object.rnorm (./node_modules/lib-r-math.js/dist/lib/libR.js:7503:54)
at repl:1:15
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:440:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
In contrast, libR.Normal().rnorm(2)
works.
Would you consider changing the functions to always return number[]
instead of number | number[]
? The fact that the return type isn’t known ahead of time will require a lot of extra coding and surely lead to a lot more run-time errors. More convenient yet would be to have two functions: one that returns number
and one that returns number[]
.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 20
Regarding your comment:
Aren’t single numbers and strings always 1-arrays in R?:
So shouldn’t returning vectors actually make porting easier?
Hi, Ellis excuse me, I actually missed this email up till now, libnmath only partially implements stuff from base and stats , and I have now made a giant todolist for all of base and stats package (hence my need for blas and lapack (partial, need only 400 routines out of 1963) , so duable, I can make a functional wrapper for you that always returns an array, meanwhile I will change the code, assume all functions will return arrays
Will now concentrate on the issues you raised for libRmath, sorry for the delay…
Hi Ellis, BLASJS (foundational library used by R, numpy, for matrix operations) ported to JS https://github.com/jacobbogers/blasjs
thumbs up for @ellis here {but then I’m an R corer, not a JS programmer at all}.
Thanks a ton, Jason. I’m quite excited about the possibilities that your library opens up. I do most of my coding in R and javascript, and this could definitely simplify some things a lot.
Fixed, pushed a new version 1.0.77 (use
npm upgrade
orgit pull
)Always force return array regardless