Interfaces/R/Jserver4R/Quirks

From J Wiki
< Interfaces‎ | R
Jump to navigation Jump to search
Overview | Methods | Examples | Quirks

Quirks

Some R and Jserver4r quirks are:

  • There are no scalars in R, for example a single number is treated as a 1-element list. However an R numeric (logical, integer, floating point) 1-element vector is set in J as a scalar.
  • an R character string is a single thing, not a list of characters. Thus it is more like a J boxed character string. In R, you cannot create the J equivalent of 2 3 $ 'abc' - a direct attempt to do so would create 2 3 $ <'abc', while working with the individual characters would create 2 3 $ ,each 'abcdef' - since each "character" is treated as a 1-element list.
  • R indexing is in origin 1.
  • R arrays are in column-major order, and the Jserver4r interface preserves this order. This is not quite the transpose of J; for example, a 2x3x4 array in R has 4 blocks, each 2x3, so is equivalent to a 4x2x3 array in J. See Array Shape in Rserver/Examples.
  • the Jserver4r interface does not yet handle R data attributes, except for dimension (i.e. shape).

Booleans

An R boolean has values FALSE (0), TRUE (1) and NA (2). Arithmetic can be done with TRUE and FALSE, while NA returns NA, for example:

> 1 + c(FALSE,TRUE,NA)
[1]  1  2 NA

A set of an R boolean in J is either a boolean list of 0 and 1, or an integer list of 0 1 and 2.

NULL

R has a NULL value, which is set in J as __ (R -Inf).