On Tue, 3 Jan 2017, Riccardo (Jack) Lucchetti wrote:
On Mon, 2 Jan 2017, Sven Schreiber wrote:
> Am 02.01.2017 um 18:13 schrieb Jan Tille:
>
>> matrix r_test2={} set skip_missing off matrix
>> r_test2={NA,0.31643,-0.11822,2.9720 ; NA, 0.96456,-0.58746,1.4570 ;
>> NA, 0.79388,0.54611,-1.0222} print r_test2
>
> OK, I see, it's the missings.
>
> More precisely: The matrix saved by R (via gretl.export) represents the
> missings as "NaN", while gretl seems to prefer "nan"
(lowercase).
>
> (also @Allin:) I manually changed all "NaN" to "nan" in the saved
file and
> then gretl's mread() accepts it.
>
> Jan, as a workaround for your case until this is fixed, could you somehow
> restrict your data to have no missings already in gretl, before you call R,
> then it should work.
Jan's example 2 runs fine on current git.
IIRC, Allin committed a few changes on the handling of NAs in mat files
shortly before Christmas.
Could you try the snapshot version?
I agree with Jack's diagnosis here: I think this problem is (mostly)
already fixed in git. The following script works OK:
<hansl>
matrix M = mnormal(3, 2)
M[1,2] = 0/0 # introduce a NaN value
print M
mwrite(M, "M.mat", 1)
foreign language=R
M1 <- gretl.loadmat("M.mat")
gretl.export(M1, "M2")
end foreign
matrix M2 = mread("M2.mat", 1)
print M2
</hansl>
The retrieved matrix M2 is the same as the original M. In addition,
this modified version also works alright:
<hansl>
open data4-1
matrix M = mnormal(3, 2)
M[1,2] = 0/0 # introduce a NaN value
print M
mwrite(M, "M.mat", 1)
foreign language=R --send-data
M1 <- gretl.loadmat("M.mat")
gretl.export(M1, "M2")
end foreign
matrix M2 = mread("M2.mat", 1)
print M2
</hansl>
Now, if you take the second version and delete the line "open
data4-1" (so that there's no dataset to send in response to the
--send-data option), then executing the script produces:
<output>
...
? end foreign
write_data_for_R: failed with err = 15
</output>
This is admittedly too cryptic, but it's a "correct" error message
in that the function write_data_for_R() has failed, for the reason
that there's nothing to write.
Allin