Re: [Rd] CHAR(STRING_ELT( - OK but CHAR(asChar(STRING_ELT( - not, why?

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue, 24 Jul 2007 09:34:50 +0200

>>>>> "BDR" == Prof Brian Ripley <ripley@stats.ox.ac.uk>
>>>>> on Mon, 23 Jul 2007 13:22:16 +0100 (BST) writes:

    BDR> I think you are asking why calling asChar on a CHARSXP gives NA_STRING. 
    BDR> In particular, the calls you mention *are* perfectly OK and work as 
    BDR> intended.

    BDR> As barely documented in R-exts, asChar is designed for vector arguments: a 
    BDR> CHARSXP is not a vector.  It gives NA_STRING for invalid inputs.
    BDR> The asXXXX family of functions are designed to coerce as necessary user     BDR> inputs, and CHARSXPs are not visible at R level.
    BDR> In general, with internal functions you are expected to
    BDR> read the code to find out what they do before using
    BDR> them.

[..............]

    BDR> There is no R '2.4', but the behaviour of asChar was the same in R 2.4.0     BDR> except for the adding of SYMSXP at

    BDR> -------------
    BDR> r40358 | maechler | 2007-01-04 11:07:04 +0000 (Thu, 04 Jan 2007) | 1 line

    BDR> eliminate CHAR_STAR in methods/src/ as per old "todo"     BDR> -------------     BDR> which message does not help me at all. Perhaps Martin can explain?

I had to " svn diff -r40357:40358 " to see :

What I did was to basically add

 	else if(TYPEOF(x) == SYMSXP)
 	    return PRINTNAME(x);

to asChar() which allowed to eliminate a macro and a similar if() in C code from methods where there's been a long standing "TODO" about this.

The only change this could have was to *not* return an NA in the 'symbol/name' cases it gave NA before.

Martin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 24 Jul 2007 - 07:37:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 Jul 2007 - 16:36:57 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.