On Mon, 24 Jun 2019, Allin Cottrell wrote:
(a propos conversion from array of strings to a vector)
I've just been working on this, replacing my original code with
something more efficient. In current git this is what happens:
<hansl>
? strings S = defarray("1", "2", "egg", "57",
"spoon")
? matrix m
? eval sscanf(S, "%m", m)
3
? print m
m (5 x 1)
1
2
nan
57
nan
</hansl>
That is, you get a column vector of (default) length equal to the
length of the array of strings, where any strings that don't convert
correctly to numeric values give nan (NA) in the output. The return
value from sscanf() tells you how many successful conversions were
made.
As you point out, this is not the same behavior as with plain string
input and matrix (%m) conversion. I'm not sure which way we should go,
but I think there's a case for "back-porting" the new behavior.
Actually that last suggestion of mine won't work. I'd forgotten how
much more complicated it is to scan an actual matrix (with an
arbitrary number of columns) from text than it is to make a column
vector out of an array of strings.
Allin