From Rainer at krugs.de  Fri Mar 28 13:42:29 2014
From: Rainer at krugs.de (Rainer M Krug)
Date: Fri, 28 Mar 2014 13:42:29 +0100
Subject: [Rd] SOLVED: creating namespaces outside packages
In-Reply-To: <53356400.7040000@gmail.com> (Duncan Murdoch's message of "Fri,
	28 Mar 2014 07:58:56 -0400")
References: <m2wqfewpsi.fsf@krugs.de> <53356400.7040000@gmail.com>
Message-ID: <m2k3bewl3e.fsf_-_@krugs.de>

Duncan Murdoch <murdoch.duncan at gmail.com> writes:

> On 28/03/2014, 7:01 AM, Rainer M Krug wrote:
>> Hi
>>
>> I would like to use namespaces outside packages, but I could not find
>> any references on how to do it (only a thread [1] which says "use a
>> package"). Using a package is not possible in my case, as I am passing
>> variables from org-mode / emacs to R and would like to avoid name
>> clashes. This is a dynamic process, and each time the code is evaluated,
>> the variable can be different.
>>
>> I am putting them at the moment into an environment which is locked, but
>> I would like to avoid name clashes, so the idea of using environments.
>>
>> So: is there a way to create a namespace and populate it as I can do
>> with an environment?
>
> I don't know what you think is the difference between a namespace and
> an environment.  I would say a namespace is one of the environments
> associated with a package, i.e. it's just an environment in a
> particular context.
>
> So depending on what you are trying to accomplish, it may be fine to
> just set up an environment.  Why do you think that won't work?

An environment is what I use at the moment, but there is one aspect I
was not happy with: accessing the original value in the environment when
it is overwritten in a higher environment in the search path. But then I
discovered then notation of using $:

,----
| env <- new.env()
| assign("value", 99, env)
| attach(env)
| value <- FALSE
| value
| env$value
`----

So I can access the original value. I only thought initially about
the :: (or is it :::) to access the objects in a namespace, which do not
work for an environment.

So: Different solution and works perfectly.

Thanks,

Rainer




>
> Duncan Murdoch
>

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20140328/bc726fd1/attachment.bin>


[Rd] SOLVED: creating namespaces outside packages
Rainer M Krug