Repository navigation
"not in" operator %!in% #4152
Description
Activity
Actually we still need to handle
!because!x%in%was just one example, another example is!x%like%y(where we would needx%!like%y). It is definitely not robust to ask users to rewrite their code from base R style to our functions so we can optimize them. And it turns out it was not that difficult to handle!. I will leave this issue open because there are upvotes, so it seems such helper function might be useful anyway.Such a function is certainly useful! I would prefer to write it as
%nin%though, which is easier to type (imho)Reacted by Gregor ThomasI would really welcome the addition of
%notin%, even if unoptimized; it is quite handy to have.- added a commit that references this issue
on Mar 7, 2021 I've been working on this and I'm wondering if someone can explain something for me. How does this function call get evaluated?
chmatch("a", c(), 5)
It returns 5, but as far as I can tell it dispatches tochmatchMainand it should return a vectorallocVector(chin?LGLSXP:INTSXP, xlen)of length 0 which islogical(0)but somehow it returns 5 from R. There's no reference to thenomatchparameter before it returns.That's happening here:
Lines 30 to 36 in 788c585
const int tablelen = length(table); if (tablelen==0) { const int val=(chin?0:nomatch), n=xlen; for (int i=0; i<n; ++i) ansd[i]=val; UNPROTECT(nprotect); return ans; } Note that this does match the corresponding
match()behavior:match("a", NULL, 5) # [1] 5
FR to propose a not-in operator
Motivation is to have a single call that we could optimise. Otherwise we have to investigate unevaluated expression tree more deeply (and in a much more complex way) to know when user is doing a not-in operation.
Pseudo code in R C api