Here's a somewhat more minimal version of your test case:
<hansl>
foreign language=R
rm(list=ls(all=T))
ma<-matrix(c(-0.25,0,1.2,0,0,0.5),nr=3,byrow=T)
ma
gretl.export(ma)
end foreign
matrix ma = mread("(a)dotdir/ma.mat")
ma
</hansl>
And this indeed provokes
Error in gretl.export(ma) : could not find function "gretl.export"
Here's why: by doing "rm(list=ls(all=T))" in R you just trashed the
definition of gretl.export.
Oh sh*t, this is embarrassing... :-/ I wasn't aware of the consequences
of the 1st line in the R code.
Thank you for figuring this out and fixing a few minor issues, Allin.
Best,
Artur