Only rectangular, do you mean? -YES > The matrix Sven constructed
(at first) was nominally rectangular
(4 x 1), but element [4,1] (represented by "?" when printed) was
not a scalar value. Of 3 possibilities (scalar, vector, matrix) Gretl has 1-st and 3-rd
R has 2nd and 3rd
what looks as scalars are actually vector of length 1
There are 6 basic types of elements:
hex ->logical ->integer->double-> complex->character
Instead of error R uses types coercion:
c("a",1) will be c("a","1")
The elements coerced to the rightmost type in the chain above
Non-numerics looks like the result of types coercion
Run to see
<R
# From help to Matrix::sparseMatrix
i <- c(1,3:8); j <- c(2,9,6:10); x <- 7 * (1:7)
(A <- sparseMatrix(i, j, x = x)) ## 8 x 10 "dgCMatrix"
summary(A)
## my addition
typeof(A)
class(A)
Am = as.matrix(A)
Am
class(Am)
typeof(Am)
R>
So A is a S4-class object
My idea is coerce such objects to
usual matrices and only export
usual matrices
Am is ready to export
Our current test, applied before attempting to build a gretl matrix
from the SEXP (call it "res") we get from an R function is.
. . .
. . . .
It will take some time
I should study Rf_isMatrix() etc.
21 жовтня 2016, 19:53:30, від "Allin Cottrell" < cottrell(a)wfu.edu >:
On Fri, 21 Oct 2016, oleg_komashko(a)ukr.net wrote:
R have a native class of objects of class 'matrix':
they can only be squared
Only rectangular, do you mean?
The matrix Sven constructed (at first) was nominally rectangular
(4 x 1), but element [4,1] (represented by "?" when printed) was
not a scalar value.
They are atomic vectors with 'dimension' attribute (2
coordinates)
Since R is an object-oriented language,
a user can specify as many new classes of data as she wants
Matrix package has many additional classes of "matrices"
It's unreal to have gretl native interface to much
classes defined in packages (about 10^4 packages in cran only)
It's more realistic to coerce some "matrix"
to a native (i. e. defined in r-base) class of objects
and only then export them
Our current test, applied before attempting to build a gretl matrix
from the SEXP (call it "res") we get from an R function is,
1) does Rf_isMatrix(res) return non-zero?
2) If so, does Rf_isReal(res) return non-zero?
where the second clause is newly added in response to Sven's
example. Only if both parts of the test pass do we try to get the
data out of the R object, using
gretl_matrix_set(m, i, j, REAL(res)[<index>]);
Do you think the above is adequate? Or if not, can you suggest a
better test?
The main goal here is not that we should be able to handle any old
object returned by an R function, but that we don't provoke an error
in libR that drags gretl down!
Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel