[Rd] setReplaceMethod creates 'object' in the userworkspace

2017-06-23 Thread Jonathan Fritzemeier
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.

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)
}
)

myNewObject <- new("newClass")
print(object)


> print(object)
[1] "newClass"

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C 
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8   
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8  
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C   
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C  

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

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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Private Variables in R5-Classes possible?

2012-02-21 Thread Claus Jonathan Fritzemeier

Hi list,

is there a way to define some kind of private Variable?

I would like to prevent the user from manipulating fields on his own, in 
order to not destroy data structures.


The problem is, that as soon as the variable exists in the environment 
it is accessible via t$secret_value.


test <- setRefClass("test", fields=list(
secret = function(value){
cat("the function was called\n")
if(missing(value)){
if(exists("secret_value", envir=.self@.xData)){
return(get("secret_value", envir=.self@.xData, inherits = F))
}
else{
return(NULL)
}
}
assign("secret_value", value=value, , envir=.self@.xData)
}
) )

> t <- test$new()
> t$secret
the function was called
NULL
> t$secret_value
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) :
"secret_value" is not a valid field or method name for reference class 
“test”

> t$secret <- "Blub"
the function was called
> t$secret_value
[1] "Blub"

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel