From kev|nu@hey @end|ng |rom gm@||@com  Sun Jul  7 11:45:19 2024
From: kev|nu@hey @end|ng |rom gm@||@com (Kevin Ushey)
Date: Sun, 7 Jul 2024 17:45:19 +0800
Subject: [Rd] API for converting LANGSXP to LISTSXP?
In-Reply-To: <20240706151009.4071a55b@parabola>
References: <CAJXgQP3+OucVzfX9fHk+-4rW1Ks1=rwpvb7WM=oSv0H8YQex_Q@mail.gmail.com>
 <20240706151009.4071a55b@parabola>
Message-ID: <CAJXgQP1Mtob6fH6LhL3RS1HxmdhFpwX6iEn83kTG18yUO2qv=A@mail.gmail.com>

In this case, Rcpp was internally converting (already-existing)
LISTSXPs to LANGSXPs using SET_TYPEOF in some places; the goal was to
allow Rcpp to continue doing this without using SET_TYPEOF just to
preserve existing behavior in an API-compliant way. I ended up doing
exactly what you suggested; thanks.

On Sat, Jul 6, 2024 at 8:09?PM Ivan Krylov <ikrylov at disroot.org> wrote:
>
> On Fri, 5 Jul 2024 15:27:50 +0800
> Kevin Ushey <kevinushey at 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



[Rd] API for converting LANGSXP to LISTSXP?
Kevin Ushey