Re: [Rd] Scoping issues

From: John Fox <jfox_at_mcmaster.ca>
Date: Sun 07 Jan 2007 - 13:57:27 GMT


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 (is.na(pos)) { # Must create it

        RcmdrEnv <- list()
        attach(RcmdrEnv, pos = length(search()) - 1)
        rm(RcmdrEnv)
        pos <- match("RcmdrEnv", search())
        }

    return(pos.to.env(pos))
    }

putRcmdr <- function(x, value)

    assign(x, value, envir = RcmdrEnv())

getRcmdr <- function(x, mode="any")

    get(x, envir = RcmdrEnv(), mode = mode, inherits = FALSE)

I hope this helps,
 John



John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

> -----Original Message-----
> From: r-devel-bounces@r-project.org
> [mailto:r-devel-bounces@r-project.org] On Behalf Of Chris Eisley
> Sent: Sunday, January 07, 2007 12:29 AM
> To: r-devel@r-project.org
> Subject: [Rd] Scoping issues
>
> Hi everyone,
>
> I'm trying to split up a large R file that implements a
> tcl/tk gui into several smaller ones. The problem is that
> the main GUI creation function defines many tclVars and
> tkframes that need to be accessible to functions that are
> currently defined in main function, but which I'd like to
> move to different source files. These files make up a
> package, so it seems that using source() is a bad idea. I
> could try argument passing, but there are a lot of arguments
> to pass in some cases.
>
> The lexical scoping is hurting me here, but I assume there's
> a good way to deal with this kind of issue. Any help is
> greatly appreciated.
>
> -Chris
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Jan 08 05:53:53 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 Mon 08 Jan 2007 - 00:31:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.