On Fri, 21 Oct 2016, Sven Schreiber wrote:
Am 20.10.2016 um 21:09 schrieb Allin Cottrell:
> On Thu, 20 Oct 2016, Sven Schreiber wrote:
>> In a more real-world case I immediately managed to crash gretl,
>> though. I'm sure it's because I'm doing foolish stuff on the R side
>> before giving gretl the result with "as.matrix()". One suspicion is
>> that perhaps R is giving me a sparse matrix which perhaps drives gretl
>> crazy. Anyway, as always, a crash should be avoided I guess...
>
> Indeed. If you could send me a crasher case I'll investigate.
>
Here you go (attention: crashes gretl for me on Windows in the sense of the
running gretl instance is gone):
<hansl-crash>
set R_functions on
foreign language=R
fcheck <- function() {
library(Matrix)
m3 <- sparseMatrix(c(1,2), c(2,3))
m2 <- matrix(rnorm(3))
return( as.matrix( c(m2, m3 ) ))
}
end foreign
matrix hey = R.fcheck()
</hansl-crash>
Apart from that I learned in the meantime that rbind() and cbind()
in R is a better way to glue matrices together.
The crash is occurring in libR, when we try to extract "real" values
from the object returned by fcheck(). We've been assuming that if
the returned object satisfies Rf_isMatrix() -- which this object
does -- then it will be real-valued, but it seems that assumption is
not warranted. I've now put in a check for real-valuedness, and we
flag an error if that fails.
I don't know enough about R's sparse matrices to say exactly what
the 'matrix' returned by fcheck consists of, but it looks kinda
funny if you print it in R itself:
<R>
library(Matrix)
m3 <- sparseMatrix(c(1,2), c(2,3))
m2 <- matrix(rnorm(3))
m1 <- as.matrix( c(m2, m3 ) )
m1
[,1]
[1,] 0.8048351
[2,] -0.9528827
[3,] 1.42894
[4,] ?
</R>
Allin