From pgilbert at bank-banque-canada.ca  Fri Mar 23 14:48:06 2007
From: pgilbert at bank-banque-canada.ca (Paul Gilbert)
Date: Fri, 23 Mar 2007 09:48:06 -0400
Subject: [Rd] how to use debug.mypkg
In-Reply-To: <m2hcsc67yb.fsf@ziti.fhcrc.org>
References: <46030191.30006@aon.at>	<5BDFDBB7-9AE2-4410-916A-3A17FA4DD3E9@jhsph.edu>	<46030891.3030207@aon.at>	<B0F5F7FF-89D9-46EF-B7D4-EA3D363D9A68@jhsph.edu>
	<m2hcsc67yb.fsf@ziti.fhcrc.org>
Message-ID: <4603DA96.4080706@bank-banque-canada.ca>

Here is the way I do something similar in my dse1 package:

..onLoad  <- function(library, section) {
    .DSEflags(list(COMPILED=TRUE, DUP=TRUE))
    invisible(TRUE)
    }

..DSEflags <- local({
    .DSE.flags <- character(0)
    function(new) {
        if(!missing(new))
            .DSE.flags <<- new
        else
            .DSE.flags
        }
})

This was suggested to me a few years ago (by Kurt I think).  It works 
well.  A call to .DSEflags() displays the settings and a list argument 
sets them.

Paul

Seth Falcon wrote:
> Benilton Carvalho <bcarvalh at jhsph.edu> writes:
> 
>> it doesn't matter where..
>>
>> just pick one of your files and set it...
>>
>> of course, your file should be listed in the Collate field (in case  
>> you changed your mind and are now using it).
> 
> One useful trick is to create an environment object in your package's
> namespace.  It is probably best to put this early in the Collate order
> so all your code can assume it is there:
> 
>    OPTIONS <- new.env(hash=TRUE, parent=emptyenv())
> 
> Then you could have, for example, a debug flag that gets a default
> value of FALSE, but can be interactively toggled.  In your package
> code you would have:
> 
>    OPTIONS$debug <- FALSE
> 
> Then you could either export this object from your namespace or, more
> conservatively, export a function to toggle.  Then an end user (or
> developer) can do:
> 
>   R> toggleDebug()
> 
> Obviously, for this to be useful, you need to have package code that
> checks if(OPTIONS$debug) and does something different.
> 
> + seth
> 
====================================================================================

La version fran?aise suit le texte anglais.

------------------------------------------------------------------------------------

This email may contain privileged and/or confidential inform...{{dropped}}



[Rd] how to use debug.mypkg
Paul Gilbert