From mtmorgan at fredhutch.org  Sun May 10 17:19:07 2015
From: mtmorgan at fredhutch.org (Martin Morgan)
Date: Sun, 10 May 2015 08:19:07 -0700
Subject: [Rd] S4 method dispatch sometimes leads to incorrect when object
 loaded from file?
Message-ID: <554F76EB.3020804@fredhutch.org>

Loading an S4 object from a file without first loading the library sometimes (?, 
the example below and actual example involves a virtual base class and the show 
generic) leads to incorrect dispatch (to the base class method).

The attached package reproduces the problem. It has

setClass("A")
setClass("B", contains="A")
setMethod("show", "A", function(object) cat("A\n"))
setMethod("show", "B", function(object) cat("B\n"))

with NAMESPACE

import(methods)
exportClasses(A, B)
exportMethods(show)

This creates the object and illustrated expected behavior

   ~/tmp$ R --vanilla --slave -e "library(PkgA); b = new('B'); save(b, 
file='b.Rda'); b"
   B

Loading PkgA before the object leads to correct dispatch

   ~/tmp$ R --vanilla --slave -e "library(PkgA); load(file='b.Rda'); b"
   B

but loading the object without first loading PkgA leads to dispatch to 
show,A-method.

   ~/tmp$ R --vanilla --slave -e "load(file='b.Rda'); b"
   Loading required package: PkgA
   A

Martin Morgan
-- 
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793


[Rd] S4 method dispatch sometimes leads to incorrect when object loaded from file?
Martin Morgan