[Rd] Possible Regression in setClassUnion between 3.5.0 and 3.6.0

Robert Harlow rh@r|ow86 @end|ng |rom gm@||@com
Tue Feb 18 15:32:35 CET 2020

I am trying to create a class union of class unions to facilitate method
dispatch. When I execute code in the global environment, everything acts as
expected, however when I put the same code in the context of a package,
selectMethod can no longer find the correct method. This first block below
puts the code in the context of a package:

fn <- "codefile.R"
        "setClass('x', slots = list(slot ='character'))",
        "setClass('y', slots = list(slot ='character'))",
        "setClass('a', slots = list(slot ='character'))",
        "setClass('b', slots = list(slot ='character'))",
        "setClassUnion('xy', c('x', 'y'))",
        "setClassUnion('ab', c('a', 'b'))",
        "setClassUnion('xyab', c('xy', 'ab'))",
        "setGeneric('f', function(object, ...) standardGeneric('f'))",
        "setMethod('f', 'xyab', function(object, ...) print('hi!'))"
    con = fn
package.skeleton(code_files = "codefile.R")
system("rm -rf anRpackage/man")
system("R CMD INSTALL anRpackage")
## fails in R 3.6.2, but works in R 3.5.0

Next, if a fresh R 3.6.2 session is started and I execute the following at
the prompt, method dispatch works as expected.

setClass("x", slots = list(slot ="character"))
setClass("y", slots = list(slot ="character"))
setClass("a", slots = list(slot ="character"))
setClass("b", slots = list(slot ="character"))
setClassUnion("xy", c("x", "y"))
setClassUnion("ab", c("a", "b"))
setClassUnion("xyab", c("xy", "ab"))
setGeneric("f", function(object, ...) standardGeneric("f"))
setMethod("f", "xyab", function(object, ...) print("hi!"))
## print's "hi!" as expected

I have also posted to stack overflow here:
(the example in this note removes devtools to make the environment

Interestingly, the issue only seems to arise when there are > 1 layer
of the class union. E.g. if I were to setMethod on "ab" instead of
"xyab", method dispatch would work as expected. I am not posting a bug
yet as it is still unclear to me if I am doing something incorrect.

My sessionInfo() is :

R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] anRpackage_1.0

loaded via a namespace (and not attached):
[1] compiler_3.6.2 tools_3.6.2

Thanks in advance for the help!

	[[alternative HTML version deleted]]

More information about the R-devel mailing list