jjwkdl jjwkdl - 1 year ago 99
Javascript Question

How can I use Javascript library in R language via "V8" packages?

I want to use RiTa.js in R language, but my code does not load the right library. How can I fix it?



ct <- v8()


ct$eval("var s = 'it was a dark and stormy night.';")

ct$eval("var r = new RiString(s);")


Error in context_eval(join(src), private$context) : ReferenceError: RiString is not defined

Answer Source

I think you will just need to make a slight adjustment to get this up and running. The RiTa JavaScript expects to be in the browser with window available. The default in R V8 is global. Fortunately we can easily change with global="window" argument.


ctx <- v8(global="window")

You should now see all the RiTa.js available for use.

  [1] "console"      "print"        "window"       "ArrayBuffer" 
  [5] "Int8Array"    "Uint8Array"   "Int16Array"   "Uint16Array" 
  [9] "Int32Array"   "Uint32Array"  "Float32Array" "Float64Array"
 [13] "DataView"     "_RiTa_LTS"    "RiTa"         "RiString"    
 [17] "RiGrammar"    "RiMarkov"     "RiWordNet"    "RiLexicon"   
 [21] "RiTaEvent"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download