[Rd] Object saved from 1.7.1, loaded in 1.8.0

John Chambers jmc at research.bell-labs.com
Thu Nov 6 15:55:45 MET 2003


Your analysis is basically correct:  As part of adapting to namespaces
and more generally to mapping correctly to classes and generic functions
from multiple packages, the class of an object now identifies the
package that class came from.  Loaded objects saved in earlier versions
will lack the package identification, though many computations will work
OK for them.

A simple fix will update objects, if the user applies it to a particular
object:

 > class(x) <- getClass(class(x))@className

This assumes that, as in your example, the relevant classes have been
defined for version 1.8 before we update the objects.

So manual intervention is fairly easy, but one would like a more
automatic mechanism, which is trickier.  Then the problem is to obey the
maxim "First, do no harm."  We should watch out for undefined classes,
inconsistent new definitions, and objects that are not really from
earlier versions.  A function, fixPre1.8(names), will be added to the
patches for 1.8.1, to let users fix loaded objects, given the names of
the objects.

John Chambers
 
"Heywood, Giles" wrote:
> 
> I am having difficulty using in 1.8.0 an object created under 1.7.1. The
> following is a 'minimal example' of the issue.  First the part in 1.7.1:
> 
> > require("methods")
> [1] TRUE
> > setClass("foo",representation("vector",label="character"))
> [1] "foo"
> > x <- new("foo",1:2,label=LETTERS[1:2])
> > save(x,file="f:/temp/test_gh.171.Rdata")
> 
> Then in 1.8.0:
> 
> > require("methods")
> [1] TRUE
> > setClass("foo",representation("vector",label="character"))
> [1] "foo"
> > load("f:/temp/test_gh.171.Rdata")
> > new("foo",x,label=x at label)
> Error in initialize(value, ...) : Initialize method returned an object of
> class "foo" instead of the required class "foo"
> > new("foo",x at .Data,label=x at label)
> An object of class "foo"
> [1] 1 2
> Slot "label":
> [1] "A" "B"
> 
> > y <- new("foo",1:2,label=LETTERS[1:2])
> > new("foo",y,label=y at label)
> An object of class "foo"
> [1] 1 2
> Slot "label":
> [1] "A" "B"
> 
> > attributes(class(x))
> NULL
> > attributes(class(y))
> $package
> [1] ".GlobalEnv"
> 
> > attributes(class(x)) <- attributes(class(y))
> > new("foo",y,label=y at label)
> An object of class "foo"
> [1] 1 2
> Slot "label":
> [1] "A" "B"
> 
> As far as I can see, the "class" attribute now has an attribute "package",
> and the absence of this attribute in objects created under 1.7.1 causes the
> problem.  This lack of 'backward compatibility' has been flagged to me as a
> bug in the package 'its' that I maintain on CRAN.  I'm not sure it's a
> bug... should I advise users to re-generate their stored objects using e.g.
> new("foo",x at .Data,label=x at label)?  Or is there something I am missing
> altogether here?
> 
> TIA
> 
> Giles Heywood
> 
> OS: NT4
> 
> R.version
> 
> platform i386-pc-mingw32
> arch     i386
> os       mingw32
> system   i386, mingw32
> status
> major    1
> minor    8.0
> year     2003
> month    10
> day      08
> language R
> 
> **********************************************************************
> This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}
> 
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list