The result of an Rserve get command may be a SEXP expression - a recursively encoded list of names and values. Such expressions should be converted to a more convenient form in J.

There are three forms in which the SEXP may be returned:

1. Rcmdrexp returns the result in the original SEXP format. This is useful for debugging, but inconvenient for practical use:

   Rcmdrexp 'x=factor(c("one","two","three","four"))'
┌────────────────────────────────────────────┬───────┐
│┌────────────────────┬───────┬──────┬──────┐│2 4 3 1│
││┌────┬───┬─────┬───┐│`levels│factor│`class││       │
│││four│one│three│two││       │      │      ││       │
││└────┴───┴─────┴───┘│       │      │      ││       │
│└────────────────────┴───────┴──────┴──────┘│       │
└────────────────────────────────────────────┴───────┘   

2. Rcmdr returns the result as a map, i.e. a 2-column matrix of names and values:

   Rcmdr 'x'
┌──────┬────────────────────┐
│class │factor              │
├──────┼────────────────────┤
│data  │2 4 3 1             │
├──────┼────────────────────┤
│levels│┌────┬───┬─────┬───┐│
│      ││four│one│three│two││
│      │└────┴───┴─────┴───┘│
└──────┴────────────────────┘

The name 'data' is used where the name is not given.

Where the SEXP is nested, the name paths are separated by dots:

   Rcmd 'data(OrchardSprays)'
   Rcmdr 'OrchardSprays'
┌────────────────┬──────────────────────────────────────────────────────────────...
│class           │data.frame                                                    ...
├────────────────┼──────────────────────────────────────────────────────────────...
│colpos          │1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 ...
├────────────────┼──────────────────────────────────────────────────────────────...
│decrease        │57 95 8 69 92 90 15 2 84 6 127 36 51 2 69 71 87 72 5 39 22 16 ...
├────────────────┼──────────────────────────────────────────────────────────────...
│rownames        │1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24...
├────────────────┼──────────────────────────────────────────────────────────────...
│rowpos          │1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 ...
├────────────────┼──────────────────────────────────────────────────────────────...
│treatment       │4 5 2 8 7 6 3 1 3 2 8 4 5 1 6 7 6 8 1 5 4 3 7 2 8 1 5 3 6 7 2 ...
├────────────────┼──────────────────────────────────────────────────────────────...
│treatment.class │factor                                                        ...
├────────────────┼──────────────────────────────────────────────────────────────...
│treatment.levels│┌─┬─┬─┬─┬─┬─┬─┬─┐                                             ...
│                ││A│B│C│D│E│F│G│H│                                             ...
│                │└─┴─┴─┴─┴─┴─┴─┴─┘                                             ...
└────────────────┴──────────────────────────────────────────────────────────────...

In nearly all cases, the map will be the most useful result. However, there are a couple of problems with this format:

In practice, these issues should not be a problem for a J program that is driving an R server, since the program can avoid using names that clash wih R internal names. In the rare case that the J result needs to be completely unambiguous, the tree format can be used.

3. Rcmdrtree returns the result as a tree. In this case, the J result exactly matches the original SEXP.

In the tree, any R identifiers are given as symbols. Any nesting is handled by boxing the data. For example:

   Rcmdrtree 'OrchardSprays'
┌──────────┬────────────────────────────────────────────────────────────────────...
│`class    │data.frame                                                          ...
├──────────┼────────────────────────────────────────────────────────────────────...
│`row.names│1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26...
├──────────┼────────────────────────────────────────────────────────────────────...
│colpos    │1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 ...
├──────────┼────────────────────────────────────────────────────────────────────...
│decrease  │57 95 8 69 92 90 15 2 84 6 127 36 51 2 69 71 87 72 5 39 22 16 72 4 1...
├──────────┼────────────────────────────────────────────────────────────────────...
│rowpos    │1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 ...
├──────────┼────────────────────────────────────────────────────────────────────...
│treatment │┌───────┬───────────────────────────────────────────────────────────...
│          ││`data  │4 5 2 8 7 6 3 1 3 2 8 4 5 1 6 7 6 8 1 5 4 3 7 2 8 1 5 3 6 7...
│          │├───────┼───────────────────────────────────────────────────────────...
│          ││`levels│┌─┬─┬─┬─┬─┬─┬─┬─┐                                          ...
│          ││       ││A│B│C│D│E│F│G│H│                                          ...
│          ││       │└─┴─┴─┴─┴─┴─┴─┴─┘                                          ...
│          │├───────┼───────────────────────────────────────────────────────────...
│          ││`class │factor                                                     ...
│          │└───────┴───────────────────────────────────────────────────────────...
└──────────┴────────────────────────────────────────────────────────────────────...

ChrisBurke/Rserve (last edited 2008-12-08 10:45:30 by )