[R] how to make read-only data frames?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Jan 12 09:27:41 CET 2008
I don't think anyone in this thread has yet mentioned ?lockBinding. That
is the underlying mechanism used to make namespace environments read-only.
You can unlock bindings, so strictly nothing in R is completely
read-only.
On Fri, 11 Jan 2008, Greg Snow wrote:
> 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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list