[R] how to make read-only data frames?

Gabor Csardi csardi at rmki.kfki.hu
Fri Jan 11 15:50:14 CET 2008


Hmmm, the only *perfect* way i know is to store the data internally
in a package, and implement all operations accessing it via
public functions. (Of course the data object itself is not exported 
from the package.) This might be overkill, but it really works.
But there might be other ways, i'm not very familiar with S4 classes,
don't they allow something like this?

Gabor

On Fri, Jan 11, 2008 at 06:37:58AM -0800, Don MacQueen wrote:
> I don't know of one.
> 
> But you could use save() to save the dataframe to a different file, 
> then remove the dataframe from .GlobalEnv, then attach the different 
> file. While not strictly speaking read-only, that should provide good 
> protection against accidental changes to the dataframe in the normal 
> course of things.
> 
> -Don
> 
> 
> At 6:13 AM -0800 1/11/08, Dan Kelley wrote:
> >QUESTION: is there a way to make objects (e.g. data frames) read-only?
> >
> >BACKGROUND: I am writing some functions that use a data frame (frequencies
> >of tidal constituents) that I want to be read-only.  I can see how to
> >accomplish this within a single function (just define the data in the
> >function), but I'm not sure how to share read-only values between
> >(un-nested) functions.  Is there a more elegant method than duplicating the
> >creation of the data frame in each function?
> >
> >
> >--
> >View this message in context: 
> >http://www.nabble.com/how-to-make-read-only-data-frames--tp14756183p14756183.html
> >Sent from the R help mailing list archive at Nabble.com.
> >
> >______________________________________________
> >R-help at r-project.org mailing list
> >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.
> 
> 
> -- 
> --------------------------------------
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
> 925-423-1062
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    UNIL DGM




More information about the R-help mailing list