From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Sat Jun 29 10:33:10 2019
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Sat, 29 Jun 2019 10:33:10 +0200
Subject: [Rd] methods package: A _R_CHECK_LENGTH_1_LOGIC2_=true error
In-Reply-To: <B499F134-0795-42AD-9CDD-C639D3FD87A0@gmail.com>
References: <CAFDcVCQOWVr0p2e2HONOy9NvqPdpoAH=HPMOEP65K-N6UjhA2g@mail.gmail.com>
 <67D2E7FE-74E3-4379-B9FB-C4028AB808DF@gmail.com>
 <CAFDcVCTARMfrJRs-KiS5UiSo=SoU8+TgPh_KE+e-zFRR0eCSFQ@mail.gmail.com>
 <23824.41030.156424.792062@stat.math.ethz.ch>
 <CAFDcVCTq-Zc49t9HrdVQB4VHhOtuaoOmpGnx9JsAy+_esene3w@mail.gmail.com>
 <03ED7150-6BF7-4E6E-AD78-B6DFACE43A97@gmail.com>
 <6334E748-4121-41E7-9CD4-3F3B2278E8DC@gmail.com>
 <23828.56742.426539.104574@stat.math.ethz.ch>
 <CAFDcVCSoHT-GxRyw-bncfnbzbG19t9sUpvPnpg=Edz_j35DiFA@mail.gmail.com>
 <23830.7740.817555.22803@stat.math.ethz.ch>
 <B499F134-0795-42AD-9CDD-C639D3FD87A0@gmail.com>
Message-ID: <23831.8774.109040.126892@stat.math.ethz.ch>

>>>>> peter dalgaard 
>>>>>     on Fri, 28 Jun 2019 16:20:03 +0200 writes:

> > On 28 Jun 2019, at 16:03 , Martin Maechler <maechler at stat.math.ethz.ch> wrote:
> > 
> >>>>>> Henrik Bengtsson 
> >>>>>>    on Thu, 27 Jun 2019 16:00:39 -0700 writes:
> > 
> >> Using:
> >> 
> >> untrace(methods::conformMethod)
> >> at <- c(12,4,3,2)
> >> str(body(methods::conformMethod)[[at]])
> >> ## language omittedSig <- omittedSig && (signature[omittedSig] != "missing")
> >> cc <- 0L
> >> trace(methods::conformMethod, tracer = quote({
> >>  cc <<- cc + 1L
> >>  print(cc)
> >>  if (cc == 31) {  ## manually identified
> >>    untrace(methods::conformMethod)
> >>    trace(methods::conformMethod, at = list(at), tracer = quote({
> >>      str(list(signature = signature, mnames = mnames, fnames = fnames))
> >>      print(ls())
> >>      try(str(list(omittedSig = omittedSig, signature = signature)))
> >>    }))
> >>  }
> >> }))
> >> loadNamespace("oligo")
> >> 
> >> gives:
> >> 
> >> Untracing function "conformMethod" in package "methods"
> >> Tracing function "conformMethod" in package "methods"
> >> Tracing conformMethod(signature, mnames, fnames, f, fdef, definition)
> >> step 12,4,3,2
> >> List of 3
> >> $ signature: Named chr [1:4] "TilingFeatureSet" "ANY" "ANY" "array"
> >>  ..- attr(*, "names")= chr [1:4] "object" "subset" "target" "value"
> >>  ..- attr(*, "package")= chr [1:4] "oligoClasses" "methods" "methods" "methods"
> >> $ mnames   : chr [1:2] "object" "value"
> >> $ fnames   : chr [1:4] "object" "subset" "target" "value"
> >> [1] "f"          "fdef"       "fnames"     "fsig"       "imf"
> >> [6] "method"     "mnames"     "omitted"    "omittedSig" "sig0"
> >> [11] "sigNames"   "signature"
> >> List of 2
> >> $ omittedSig: logi [1:4] FALSE TRUE TRUE FALSE
> >> $ signature : Named chr [1:4] "TilingFeatureSet" "ANY" "ANY" "array"
> >>  ..- attr(*, "names")= chr [1:4] "object" "subset" "target" "value"
> >>  ..- attr(*, "package")= chr [1:4] "oligoClasses" "methods" "methods" "methods"
> >> Error in omittedSig && (signature[omittedSig] != "missing") :
> >>  'length(x) = 4 > 1' in coercion to 'logical(1)'
> >> Error: unable to load R code in package 'oligo'
> >> 
> > 
> > Thank you, Henrik, nice piece of using trace() .. and the above
> > is useful for solving the issue --  I can work with that.
> > 
> > I'm  already pretty sure the wrong code starts with
> > 
> >    omittedSig <- sigNames %in% fnames[omitted] # ....

my  "pretty sure"  statement above has proven to be wrong ..

> > -------------
> > 
> 
> I think the intention must have been that the two "ANY" signatures should change to "missing". 

Definitely.

> However, with the current logic that will not happen, because
> 
> > c(F,T,T,F) &&  c(T,T)
> [1] FALSE
> 
> Henrik's non-fix would have resulted in
> 
> > c(F,T,T,F) &  c(T,T)
> [1] FALSE  TRUE  TRUE FALSE
> 
> which is actually right, but only coincidentally due to recycling of c(T,T). Had it been c(F,T) then it would have been expanded to c(F,T,F,T) which would be the opposite of what was wanted.
> 
> Barring NA issues, I still think 
> 
> omittedSig[omittedSig] <- (signature[omittedSig] != "missing")
> 
> should do the trick.

yes, (most probably).  I've found a version of that which should
be even easier to "read and understand", in  svn commit 76753 :

svn diff -c 76753 src/library/methods/R/RMethodUtils.R

--- src/library/methods/R/RMethodUtils.R	(Revision 76752)
+++ src/library/methods/R/RMethodUtils.R	(Revision 76753)
@@ -342,8 +342,7 @@
              gettextf("formal arguments (%s) omitted in the method definition cannot be in the signature", bad2),
              call. = TRUE, domain = NA)
     }
-    else if(!all(signature[omittedSig] == "missing")) {
-        omittedSig <- omittedSig && (signature[omittedSig] != "missing")
+    else if(any(omittedSig <- omittedSig & signature != "missing")) {


BTW:  I've marked this --- and the  runmed() seg.fault + na.action
change ---  as something to be added to R 3.6.1 patched,  as I
deemed I should obey the "code freeze" rule in both cases.

Martin


> > *Still*  I cannot understand why in my case (and probably Peter,
> > as he also said he can't reproduce),
> > the  conformMethod() function is not even called  when I run
> >     loadNamespace("oligo").
> > 
> > As conformMethod() is *only* called from setMethod(), I've
> > started trace()ing  setMethod() and indeed, it is *only* called one,
> > and not with oligo methods/generics,... 
> > 
> > Henrik, do you per chance not install packages in the usual way,
> > i.e., do you install them without saving all the pre-computed
> > classes and methods tables etc,
> > and that would be *why* these setMethod() etc are only called at
> > this point in time ?
> > 
> > Martin
> 
> -- 
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
> 
> 
> 
> 
>



[Rd] methods package: A _R_CHECK_LENGTH_1_LOGIC2_=true error
Martin Maechler