From sfalcon at fhcrc.org  Thu Oct 26 19:20:44 2006
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Thu, 26 Oct 2006 10:20:44 -0700
Subject: [Rd] NA handling in as.character applied to a list
In-Reply-To: <x2d58gt4y6.fsf@turmalin.kubism.ku.dk> (Peter Dalgaard's message
	of "26 Oct 2006 00:18:25 +0200")
References: <m24ptsay46.fsf@ziti.local> <x2d58gt4y6.fsf@turmalin.kubism.ku.dk>
Message-ID: <m28xj32dub.fsf@ziti.local>

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));




[Rd] NA handling in as.character applied to a list
Seth Falcon