Hello,
I'm testing the feature from the section "Further use of the R library"
of the gretl guide (36.7), namely that I can define my own R functions
in a foreign block and call them later. (Which is great!) I'm struggling
with some limitations when I want to get matrices back, and I'm not sure
whether those are bugs or not. Sometimes I'm only getting the first
element of the return matrix, and sometimes there seems to be some
unwanted rounding going on.
Below are some examples (sorry a bit long, but just because it's
repetitive).
Thanks,
Sven
<hansl>
set R_functions on
# matrix in / matrix out (or scalar in /scalar out)
foreign language=R
check1 <- function(x) {
options(digits=10)
return(x)
}
end foreign
# scalar in / matrix out (or matrix in / matrix out)
foreign language=R
check2 <- function(x) {
options(digits=10)
z <- c(x, x)
return(z)
}
end foreign
# both scalar and matrix in / matrix out
foreign language=R
check3 <- function(x, y) {
options(digits=10)
z <- c(x, y)
return(z)
}
end foreign
### calls from hansl
scalar ins = 10
matrix inm = {123456.9, 0}
matrix heym = R.check1(inm) # works
eval heym
scalar heys = R.check1(ins) # works
eval heys
matrix hus = R.check2(ins) # fails
eval hus
matrix hum = R.check2(inm) # fails
eval hum
matrix ouf = R.check3(ins, inm) # fails
eval ouf
## for comparison:
foreign language=R
options(digits=10)
print(c( c(123456.9, 0), c(123456.9, 0) ))
end foreign
</hansl>