[R] Write protecting objects

Thomas Lumley tlumley at u.washington.edu
Fri Jul 12 18:50:40 CEST 2002


On Fri, 12 Jul 2002, Adaikalavan Ramasamy wrote:

> Is there a function to write protect a matrix  or list ?
>
> I have considered making a duplicate copy. But I am wondering if
> alternatives exist. Thanks.
>

You could do this up to a point by defining a class with nonfunctional
subscripting methods
> data(trees)
> class(trees)<-c("nowrite",class(trees))
> "[<-.nowrite"<-function(x,...) {stop("Write protected")}
> "[[<-.nowrite"<-function(x,...) {stop("Write protected")}
> trees[3,4]<-4
Error in "[<-.nowrite"(*tmp*, 3, 4, value = 4) :
        Write protected
> trees[3,]<-trees[2,]
Error in "[<-.nowrite"(*tmp*, 3, , value = trees[2, ]) :
        Write protected

but this can't protect you against
> data(hills)
> trees<-hills
and it doesn't even seem to work on $
> "$<-.nowrite"<-function(x,...) {stop("Write protected")}
> trees$Girth<-trees$Volume

You probably want a duplicate copy.

	-thomas



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list