[R] STRING_PTR_RO compared to STRING_ELT

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Mon Oct 5 21:40:11 CEST 2026


В Mon, 05 Oct 2026 16:35:55 +0100
"Tim Taylor" <tim.taylor using hiddenelephants.co.uk> пишет:

> Apart from different ergonomics is there anything worth being aware
> of when using STRING_PTR_RO versus STRING_ELT for getting CHARSXP?

Iris Simmons gave an excellent explanation. The only thing left to note
is that some ALTREP classes currently have STRING_ELT methods that
return CHARSXPs not protected from garbage collection:

https://bugs.r-project.org/show_bug.cgi?id=19135
https://github.com/gagolews/stringi/issues/354
https://github.com/tidyverse/vroom/pull/638
https://github.com/apache/arrow/issues/51198

If your code can be expected to process strings from vroom or arrow and
you chose STRING_ELT (instead of STRING_PTR_RO which would materialise
the vector), you may need to add some workarounds.

-- 
Best regards,
Ivan



More information about the R-help mailing list