Am 24.01.2018 um 18:45 schrieb Allin Cottrell:
On Wed, 24 Jan 2018, Artur T. wrote:
> Let's take [Allin's] example for the moment (see below).
>
>> <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>
>
> This example returns here and on 2 other Ubuntu machines -- assuming
> that I start gretl by launching "gretl" via the terminal:
>
> <terminal>
> To use Rlib, the variable R_HOME must be set
> </terminal>
Let me try to clarify this. The error message above is coming from
gretl, but the requirement that R_HOME be defined (correctly) in the
user's environment actually comes from the R library. If gretl were to
proceed regardless you would instead see this message from libR:
"Fatal error: R home directory is not defined"
I've been assuming that it's easy enough for people who wish to use R
from gretl to arrange for R_HOME to be defined, e.g. in ~/.bashrc.
However, since gretl requires that the path to libR is set, there's a
case for saying that, in case R_HOME is not set, gretl should infer this
value from the known libR path and push it into the environment on the
user's behalf. That facility is now added in git.
Thank you for adding this!
> As said, would I launch it by "R_HOME=/usr/lib/R gretl"
it would work.
Yes, that works. But I thought you were saying (earlier) that once you
defined R_HOME something else stopped working -- but I'm not clear on
what that something else was, which is why I requested a minimal test case.
Please find attached a minimal test case (tested on latest git on ubuntu
17.10). In this example I just call R via the foreign-block and want to
export some matrix. The error I obtain is
"Error in gretl.export(ma) : could not find function "gretl.export"
External command failed"
Now (after the git update?) this error occurs irrespective of whether
gretl is launched by "gretl" or "R_HOME=/usr/lib/R gretl"
There is another weird thing:
(i) run my example script "RcommGretl.inp", and see the error
(ii) run the following script within the same gretl session (listing
39.1. from the manual) and see the the same error msg.
<hansl>
open bjg.gdt
foreign language=R --send-data
y <- gretldata[, "lg"]
strmod <- StructTS(y)
compon <- as.ts(tsSmooth(strmod))
vars <- as.matrix(strmod$coef)
gretl.export(compon)
gretl.export(vars)
end foreign
append @dotdir/compon.csv
vars = mread("vars.mat", 1)
</hansl>
(iii) close everything and re-open gretl
(iv) run the hansl script from listing 39.1 and see that it _WORKS_ this
time...