[Rd] NA handling in as.character applied to a list
Seth Falcon
sfalcon at fhcrc.org
Thu Oct 26 19:20:44 CEST 2006
Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:
> Hmm...
>
>> as.character(v)
> [1] NA "NA" "NA"
>
> This does look like a leftover from times when there was no character
> NA in the language. It is the kind of thing you need to be very
> careful about fixing though. (I have a couple of scars from
> as.character on formulas when introducing backtick quoting.)
Well, I guess that's an argument for leaving the inconsistent
behavior. In case there is interest in fixing, here is a patch I was
playing with. It doesn't address the nasties with dput.
index 8eec5c3..787c230 100644
--- a/src/main/coerce.c
+++ b/src/main/coerce.c
@@ -1041,6 +1041,14 @@ #if 0
else if (isSymbol(VECTOR_ELT(v, i)))
SET_STRING_ELT(rval, i, PRINTNAME(VECTOR_ELT(v, i)));
#endif
+ else if ((length(VECTOR_ELT(v, i)) == 1) &&
+ (isInteger(VECTOR_ELT(v, i)) ||
+ isReal(VECTOR_ELT(v, i)) ||
+ isLogical(VECTOR_ELT(v, i)))) {
+ SET_STRING_ELT(rval, i,
+ STRING_ELT(coerceVector(VECTOR_ELT(v, i),
+ STRSXP), 0));
+ }
else
SET_STRING_ELT(rval, i,
STRING_ELT(deparse1line(VECTOR_ELT(v, i), 0), 0));
More information about the R-devel
mailing list