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

Martin Maechler maechler at stat.math.ethz.ch
Tue Jul 24 09:34:50 CEST 2007

>>>>> "BDR" == Prof Brian Ripley <ripley at 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.


More information about the R-devel mailing list