[Rd] API for converting LANGSXP to LISTSXP?

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Sat Jul 6 14:10:09 CEST 2024


On Fri, 5 Jul 2024 15:27:50 +0800
Kevin Ushey <kevinushey using gmail.com> wrote:

> A common idiom in the R sources is to convert objects between LANGSXP
> and LISTSXP by using SET_TYPEOF. However, this is soon going to be
> disallowed in packages.

Would you mind providing an example where a package needs to take an
existing LISTSXP and convert it to a LANGSXP (or vice versa)? I think
that Luke Tierney intended to replace the uses of
SET_TYPEOF(allocList(...), LANGSXP) with allocLang(...).

At least it's easy to manually convert between the two by replacing the
head of the list using LCONS(CAR(list), CDR(list)) or CONS(CAR(lang),
CDR(lang)): in a call, the rest of the arguments are ordinary LISTSXPs.

-- 
Best regards,
Ivan



More information about the R-devel mailing list