Skip to content
Back to formatted view

Raw Message

Message-ID: <476539B4.7050302@stats.uwo.ca>
Date: 2007-12-16T14:44:04Z
From: Duncan Murdoch
Subject: clean programming
In-Reply-To: <20071216152520.qo8jnpahvk0k0w4k@icare.u-paris10.fr>

On 16/12/2007 9:25 AM, cgenolin at u-paris10.fr wrote:
> Hello the list,
> 
> I am trying to write a "cleanProgramming" function to test the 
> procedure I use. For example, I want to be sure that I am not using 
> globals variables. The function "findGlobals" detect that.
> 
> To list the globals used in function "fun", the syntax is : 
> "findGlobals(fun,FALSE)$variable"
> 
> My problem is that I want to use it in a function, something like :
> 
> cleanProg <- function(name){
>   if(length(findGlobals(name,FALSE)$variable>0){
>     cat("Warnings: there is globals is function ",name,"\a\n")
>   }
> }
> 
> But findGlobals take a function as first argument, not a variable 
> containing a function name.
> 
> Anyway to solve that?

Use get() to find an object with a given name.  You need to be careful 
to specify where it should look (the envir argument); typically 
parent.frame() is appropriate, but your cleanProg function should allow 
the user to override this.

Duncan Murdoch