Re: [Rd] Scoping issues

From: Chris Eisley <>
Date: Mon 08 Jan 2007 - 18:50:47 GMT

Hello Prof Ripley,

Prof Brian Ripley wrote:
> I don't undersand what the issues are, but he actually said

>>> These files make up a package,

> and all the source files on an R packages are concatenated and loaded
> into a single environment. So my understanding of the answer to
>>> I assume there's a good way to deal with this kind of issue.

> is 'yes, build an R package'.

My code is built as a package, but having a package doesn't seem to prevent the kind of problem I'm running into. My code is currently structured as such:

ui.main <- function() {

	ui.func1 <- function {
	ui.widget1 <- tkframe(...)
	ui.widget2 <- tkframe(...)
	ui.widget3 <- tkframe(...)


I'd like to move the definition of ui.func1 and those of other functions like it to seperate source files, since my main "ui" source file is getting quite large. The variables need to be available to several other functions that I'd like to move to separate source files. Since the tkframe variables can't be created in the environment of ui.main, I'm not sure how to get around this problem without a lot of argument passing.

> On Sun, 7 Jan 2007, John Fox wrote:

Hello John,

>> Dear Chris,
>> If I correctly understand what you want to do, the Rcmdr package uses the
>> following functions (slightly modified from original version 
>> contributed by
>> Philippe Grosjean) to solve a similar problem:
>> RcmdrEnv <- function() {
>>    pos <-  match("RcmdrEnv", search())
>>    if ( { # Must create it
>>        RcmdrEnv <- list()
>>        attach(RcmdrEnv, pos = length(search()) - 1)
>>        rm(RcmdrEnv)
>>        pos <- match("RcmdrEnv", search())
>>        }
>>    return(
>>    }
>> putRcmdr <- function(x, value)
>>    assign(x, value, envir = RcmdrEnv())
>> getRcmdr <- function(x, mode="any")
>>    get(x, envir = RcmdrEnv(), mode = mode, inherits = FALSE)

I think I understand what's going on here, but it seems like a rather arcane solution to such a basic problem. It seems as if I'm trying to code in a way that's incompatible with R's scoping.

-Chris mailing list Received on Tue Jan 09 11:18:10 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 09 Jan 2007 - 06:31:11 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.