0

I've been trying to access and fool around with data frames using OpenCPU's JS library for ages now, but no matter what I try, I can't seem to get it to work. Here's my latest code sample, very straightforward:

var dat = [1, 2, 3];
var dat2 = ["a", "b", "c"];

var req = ocpu.call("data.frame", { x: dat, y: dat2 }, 
  function(session)  {
    session.getObject(function(data)  {
      alert(data);
    });
});

Unfortunately, all I get is [object Object],[object Object],[object Object] as the output. What do? The data frame is being created properly; session.getConsole shows me the correct console output. Why won't it return properly? I've tried calling data.frame, as.data.frame on JSON data as well; same problem. I'd appreciate some help.

Cheers.

joran
  • 169,992
  • 32
  • 429
  • 468
vinit_ivar
  • 610
  • 6
  • 16
  • 2
    Instead of alert(data) do console.log(data). Then the dev console will show you the details about the object you receive. – Raffael Mar 15 '15 at 16:04
  • @Raffael, I tried that - unfortunately, it shows up as `Array [Object, Object, Object]`. I can access the elements within the array, so the data is still there - but not with the same syntax as a data frame, and, more importantly, I can't pass it to other functions. Any suggestions? – vinit_ivar Mar 15 '15 at 18:29
  • Yes ... learn some JavaScript and R and then go back to reading the documentary on OpenCPU or http://www.joyofdata.de/blog/introduction-to-opencpu-for-r-on-ec2-with-python/. You lack understanding of the stuff you are dealing with. – Raffael Mar 15 '15 at 19:10

1 Answers1

3

That seems like the correct response because alert needs to coerse your dataset, which consist of three rows (objects), into a string.

What exactly are you after? Try using console.log instead of alert to inspect your data. If you want to alert the data in it's JSON form, use use: alert(JSON.stringify(data));

Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
  • I'm trying to get a data frame that I can pass as an argument to a further ocpu.call(). This data can't be passed; the R backend has no idea what to do with it. – vinit_ivar Mar 17 '15 at 12:25
  • 1
    If you pass the `session` object as an argument to a subsequent call the library will automatically figure it out. – Jeroen Ooms Mar 17 '15 at 20:47