>>>>> Jonathan Fritzemeier <clausjonathan.fritzeme...@uni-duesseldorf.de> >>>>> on Fri, 23 Jun 2017 16:15:30 +0200 writes:
> Hi, > I recognized that the function 'setReplaceMethod' is creating a > character vector in the user workspace having the name (e.g. "newClass") > of the class used as value. If you can sort out a mistake by myself, I > would like you to file a bug report. Yes, a mistake by yourself (and really not fit for R-devel, but rather for R-help to which I follow up now) > BBFN, > Jonathan > setClass("newClass", representation(value="numeric")) > > setMethod(f = "initialize", signature = "newClass", > definition = function(.Object){ > .Object@value <- 1 > return(.Object) > }) > > setGeneric(name = "myValue", > def = function(object) { standardGeneric("myValue") } > ) > setGeneric(name = "myValue<-", > def = function(object, value) { standardGeneric("myValue<-") } > ) > > setMethod("myValue", signature(object = "newClass"), > function(object) { > return(object@value) > } > ) > setReplaceMethod("myValue", signature = (object = "newClass"), > function(object, value) { > object@value <- value > return(object) > } > ) Q: what do you think happens with the above [last setReplaceMethod() call] ? A: it creates an R object named 'object' in the globalenv (or the package if this would go into a package) If just replace '(object = "newClass")' by '"newClass"' things should be fine. {{ Removing all the completely redundant return(.), i.e. return implicitly rather than via an extra function call would also make the code "cleaner" and more R-like }} Best, Martin > myNewObject <- new("newClass") > print(object) > > > > print(object) > [1] "newClass" > ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.