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

From: Oleg Sklyar <osklyar_at_ebi.ac.uk>
Date: Mon, 23 Jul 2007 12:14:30 +0100


Any idea why CHAR(asChar(STRING_ELT( produces NA whereas CHAR(STRING_ELT( gets a pointer to a string? It's generally expected that STRING_ELT should already be a character, but why the coercion does not work? Here is a simple example (consistent over R2.5.1-R2.6 rev 42284, I didn't check earlier versions, but it used to be different in 2.4):

install.packages("inline")

library(inline)

sig <- signature(x="character")
code1 <- "
  for (int i = 0; i < LENGTH(x); i++ )
    Rprintf(\"%s\\n\", CHAR(STRING_ELT(x, i)));   return R_NilValue;
"

code2 <- "
  for (int i = 0; i < LENGTH(x); i++ )
    Rprintf(\"%s\\n\", CHAR(asChar(STRING_ELT(x, i))));   return R_NilValue;
"

setCMethod(c("p1","p2"), list(sig,sig), list(code1,code2))

#----------------------------------------------------------
p1(c("str1", "str2"))
# str1
# str2
# NULL

p2(c("str1", "str2"))
# NA
# NA
# NULL
-- 
Dr. Oleg Sklyar * EBI-EMBL, Cambridge CB10 1SD, UK * +441223494466

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 23 Jul 2007 - 11:16:44 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 Mon 23 Jul 2007 - 12:36:39 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.