From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Sat Feb 12 10:58:05 2022
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Sat, 12 Feb 2022 10:58:05 +0100
Subject: [Rd] str2lang throws error when the string is empty
In-Reply-To: <3D923E32-CF64-4AC5-BE66-61048A30A55B@gmail.com>
References: <3D923E32-CF64-4AC5-BE66-61048A30A55B@gmail.com>
Message-ID: <25095.33965.301976.460342@stat.math.ethz.ch>

>>>>> Dipterix Wang 
>>>>>     on Fri, 11 Feb 2022 06:55:44 -0500 writes:

    > Hi,

    > str2lang("") raises an error in current version. 

on purpose.

    > Would it
    > be good if it returns a missing value expression? 

Well, others may be able to better explain why "the empty name"
aka your "missing value expression" or just "the missing"   is a
"dangerous" object  and ideally it would not be available at all
on the R level.  OTOH, it is available e.g. via alist(), maybe
slightly "less ugly" as    alist(.=)$.

but I don't think there are really good use cases.
(see below)

    > One use-case would be to build an expression that subsets an
    > array:

    > # Expected: x[index1, ] 
    > as.call(list(quote(`[`), quote(x), quote(index1), str2lang("")))

    > Right now I'm using the following, which is ugly
    > as.call(list(quote(`[`), quote(x), quote(index1), alist(x=)[[1]]))

Well, in such cases, much less ugly than both your version is to
use  substitute(),
here e.g.,

  > substitute(x[I,], list(I = quote(index1)))
  x[index1, ]
  >

    > Thanks, - Dipterix

You are welcome,
Martin



{Please, for next time do use  text/plain  e-mail : }

    > [[alternative HTML version deleted]]



[Rd] str2lang throws error when the string is empty
Martin Maechler