[R] STRING_PTR_RO compared to STRING_ELT
Iris Simmons
|kw@|mmo @end|ng |rom gm@||@com
Mon Oct 5 18:01:15 CEST 2026
STRING_PTR_RO(x)[i] will not check bounds and will not check that the
element is not NULL and not a free node. STRING_PTR_RO only works on
standard vectors, and will not work on alternate vector representations.
Also, it will return (const SEXP *) (void *) 1 when the character vector is
of length 0, or may return a pointer to a random place in memory. In
general, I would suggest
const SEXP *y = NULL;
if (Rf_xlength(x)) y = STRING_PTR_RO(x);
or something similar in order to avoid anything weird involving 0 length
access.
I do not know of any other differences to note.
On Mon, Oct 5, 2026, 11:36 Tim Taylor <tim.taylor using hiddenelephants.co.uk>
wrote:
> Apart from different ergonomics is there anything worth being aware of
> when using STRING_PTR_RO versus STRING_ELT for getting CHARSXP?
>
> Tim
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list