Hello, the last command (isGeneric) in following R-code (attached) produces different output, depending on wheter 1.8.0 alpha or 1.7.1 is used. Is that to be expected ? Both R Versions were started with option vanilla --------------------------------------------------- R.1.7.1: ---------------------------------------------------> version_ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 7.1 year 2003 month 06 day 16 language R> isGeneric("foo")[1] FALSE> setClass("woo", representation(foo="character"), prototype = list(foo ="text"))[1] "woo"> if(!isGeneric("foo")) setGeneric("foo", function(object) standardGeneric("foo"))[1] "foo"> setMethod("foo", "woo", function(object) object@foo)[1] "foo"> isGeneric("foo")[1] TRUE --------------------------------------------------- R 1.8.1: ---------------------------------------------------> version_ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status alpha major 1 minor 8.0 year 2003 month 09 day 25 language R> isGeneric("foo")[1] FALSE> setClass("woo", representation(foo="character"), prototype = list(foo="text"))[1] "woo"> if(!isGeneric("foo")) setGeneric("foo", function(object) standardGeneric("foo"))[1] "foo"> setMethod("foo", "woo", function(object) object@foo)[1] "foo"> isGeneric("foo")[1] FALSE --------------------------------------------------- --------------------------------------------------- Greetings, Thomas Stabla -------------- next part -------------- version isGeneric("foo") setClass("woo", representation(foo = "character"), prototype = list(foo = "text")) if(!isGeneric("foo")) setGeneric("foo", function(object) standardGeneric("foo")) setMethod("foo", "woo", function(object) object@foo) isGeneric("foo")
Thomas Stabla <a9265@stud.uni-bayreuth.de> writes:> R 1.8.1: > --------------------------------------------------- > > > version > _ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status alpha > major 1 > minor 8.0 > year 2003 > month 09 > day 25 > language RDid you get that from rsync? (These have the erroneous "alpha" designation, the tarballs should say "beta" since Wednesday.) If so, please consider testing the tarball instead since that allows us to catch packaging errors too.> > isGeneric("foo") > [1] FALSE > > setClass("woo", representation(foo="character"), prototype = list(foo="text")) > [1] "woo" > > if(!isGeneric("foo")) setGeneric("foo", function(object) standardGeneric("foo")) > [1] "foo" > > setMethod("foo", "woo", function(object) object@foo) > [1] "foo" > > isGeneric("foo") > [1] FALSEHmm. This is still in the current sources. Doesn't quite look deliberate, but it works to use the explicit> isGeneric("foo",environment())[1] TRUE What appears to be happening is that we don't get further than this:> isGenericfunction (f, where = -1, fdef = NULL, getName = FALSE) { if (is.null(fdef)) { if (identical(where, -1)) { where <- findFunction(f) if (length(where) == 0) return(FALSE) findFunction(f) goes looking in the topenv(parent.frame()) but topenv is using parent.env() and that goes through the *lexical* scope I believe, so we end up looking for "foo" in the methods namespace. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
Thomas Stabla wrote:> > Hello, > > the last command (isGeneric) in following R-code (attached) produces > different output, depending on wheter 1.8.0 alpha or 1.7.1 is used. > Is that to be expected ?This is a bug, but one that may be worth understanding. In order to work properly with namespaces, many of the functions in the package have changed the default for `where' arguments, from a value meaning "search in the search list" to one meaning "search in the top environment of the call to this function". The isGeneric function seems to have been overlooked. If other examples like this arise, let us know. As Peter Dalgaard's message mentioned, the workaround is to provide an explicit `where' argument with the environment in which to start the search (typically .GlobalEnv). And calls to these functions from within other packages may need to provide a `where' argument, unless the right default is to look in the namespace of the package. John> > Both R Versions were started with option vanilla > > --------------------------------------------------- > R.1.7.1: > --------------------------------------------------- > > > version > _ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 1 > minor 7.1 > year 2003 > month 06 > day 16 > language R > > isGeneric("foo") > [1] FALSE > > setClass("woo", representation(foo="character"), prototype = list(foo ="text")) > [1] "woo" > > if(!isGeneric("foo")) setGeneric("foo", function(object) standardGeneric("foo")) > [1] "foo" > > setMethod("foo", "woo", function(object) object@foo) > [1] "foo" > > isGeneric("foo") > [1] TRUE > > --------------------------------------------------- > R 1.8.1: > --------------------------------------------------- > > > version > _ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status alpha > major 1 > minor 8.0 > year 2003 > month 09 > day 25 > language R > > isGeneric("foo") > [1] FALSE > > setClass("woo", representation(foo="character"), prototype = list(foo="text")) > [1] "woo" > > if(!isGeneric("foo")) setGeneric("foo", function(object) standardGeneric("foo")) > [1] "foo" > > setMethod("foo", "woo", function(object) object@foo) > [1] "foo" > > isGeneric("foo") > [1] FALSE > > --------------------------------------------------- > --------------------------------------------------- > > Greetings, > Thomas Stabla > > ------------------------------------------------------------------------ > Name: code.R > code.R Type: Plain Text (TEXT/PLAIN) > Encoding: BASE64 > > ------------------------------------------------------------------------ > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel