Skip to content
Back to formatted view

Raw Message

Message-ID: <200504081000.22243.deepayan@stat.wisc.edu>
Date: 2005-04-08T15:00:22Z
From: Deepayan Sarkar
Subject: restrict namespace inside functions?
In-Reply-To: <20050408145022.42396.qmail@web31315.mail.mud.yahoo.com>

On Friday 08 April 2005 09:50, Vivek Rao wrote:
> Is there a way to exclude from the namespace all
> variables other than function arguments and local
> variables? For example, I would like the following
> code
>
> a = 2.0
> mult <- function(x)
> {
>    pi = 3.14
>    return(pi*a*x)
> }
> print(mult(10.0))
>
> to say "a not found" rather than using a = 2.0 inside
> function mult. Thanks.

Depending on why you want to do this, it might be enough to say

environment(mult) <- new.env(parent = NULL)

HTH,

Deepayan