[R] Set environment name
ggrothendieck at gmail.com
Wed Jul 14 14:31:30 CEST 2010
On Wed, Jul 14, 2010 at 7:53 AM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
> On Tue, 13 Jul 2010, thmsfuller066 at gmail.com wrote:
>> Hello All,
>> ?environmentName shows how to get the environment name. But I don't
>> see how to set the name in the first place. Could you tell me where to
>> look for the function that set the environment name?
> It is not AFAIK possible from R code. environmentName() will give the name
> which has been assigned at C level, but names(), which would otherwise work,
> is disabled for non-vector objects.
> The underlying reason is the unusual copying semantics of environments -- it
> makes little sense to allow the name to be changed.
> I do wonder why you would want this: if there is a good reason then we could
> perhaps allow new.env() to set the name. But I added environmentName() to
> be able programatically to identify system environments such as packages and
> namespaces, especially the latter.
When you are dealing with nested structures its easy to lose track of
where you are. If you don't know you are typically reduced to
performing an ls on the environment to look at its objects in the hope
that that will give you an idea. If one could name them then it
might help in figuring this out at times. Note that it would be nice
to not only be able to name environments created explicitly via
new.env() but also ones created implicitly within a function. For
example, a common problem is that such an environment gets retained
due to a function outputting a formula whose environment is the local
environment of the function that created it. If it were possible to
label the environment in the execution instance that created it it
might be helpful.
More information about the R-help