On Tue, 23 Jan 2018, Artur Tarassow wrote:
Dear all,
I am facing the following problem. I am calling via the foreign-environment
R-code from inside gretl/hansl, compute some matrices and use the
gretl.export() function to export these matrices. This works fine even though
the terminal gives me the note "To use Rlib, the variable R_HOME must be set"
(more on this below).
Next, but within the same session, I want to call an R-function which is
called by some gretl function I've written. However, I obtain the error
<error>
The symbol 'R.cvglmnet_R' is undefined
*** error in function glmnet, line 40
</error>
This is due to the fact, that R_HOME doesn't being set properly even though
the path to the R library is set correctly (on Ubuntu 17.10 it's:
"/usr/lib/R/lib/libR.so").
Hmm, maybe we could try setting R_HOME from within gretl if we seem to
have a valid spec for libR, but I'm not sure how cross-platform that
would be.
However, in case I open gretl via the terminal by
at@atdesktop:~$ R_HOME=/usr/lib/R gretl
I can call the R.cvglmnet function properly. HOWEVER, in this case I obtain
the error:
<error>
Error in gretl.export(sdy) : could not find function "gretl.export"
External command failed
</error>
To sum up: I can't do both things at the same time :-/
Any hints on this? I am using Ubuntu 17.10 (it also happens on 17.04) using
current the git version of gretl.
Artur, if you could give us a minimal test case that would be very
helpful.
In case it's of any relevance, here's an example of usage of a
function defined in R:
<hansl>
nulldata 100
set verbose off
set R_functions on
foreign language=R --quiet
moments_R <- function(x) {
library(moments)
s <- skewness(x)
k <- kurtosis(x)
matrix(c(s,k), nrow=1, ncol=2)
}
end foreign
series x = normal()
matrix Rmom = R.moments_R(x)
print Rmom
matrix gmom = {skewness(x), kurtosis(x)+3}
print gmom
</hansl>
I can rewrite the tail end of moments_R() to read
m <- matrix(c(s,k), nrow=1, ncol=2)
gretl.export(m)
m
so as to "export" the moments matrix as well as returning it directly.
There's obviously not much point in that; I mention it simply because
it works OK and it seemed you were saying this sort of thing didn't
work.
Allin