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

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Fri, 11 Jan 2008 21:32:53 -0700

I think what you want to do is define your data frame(s) in an environment that is not on the standard search path and then create your functions so that they use the same environment or their environments inherit from the one with the data frames.  

For large projects the best way to do this is probably create a package and use a namespace so that the data frame is available to your exported functions but not exported itself.  

you could also use functions like new.environment and environment to explicitly set the environment (this does not make the data frame strictly read only, just harder to change or overwrite by accident).  

Another approach for small quick cases is to use the local function, it will create a local environment then you can the data frame and a list of functions that use it.  

Hope this helps,


From: r-help-bounces_at_r-project.org on behalf of Dan Kelley Sent: Fri 1/11/2008 7:13 AM
To: r-help_at_r-project.org
Subject: [R] how to make read-only data frames?

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. [[alternative HTML version deleted]]
______________________________________________
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.
Received on Sat 12 Jan 2008 - 04:40:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Jan 2008 - 10:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive