[Rd] str2lang throws error when the string is empty
    Martin Maechler 
    m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
       
    Sat Feb 12 10:58:05 CET 2022
    
    
  
>>>>> 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]]
    
    
More information about the R-devel
mailing list