Re: [Rd] Scoping issues

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sun 07 Jan 2007 - 14:45:37 GMT

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'.

If you really don't want to do that, you cannot easily use source() with such an environment as RcmdrEnv(), but you can use sys.source().

On Sun, 7 Jan 2007, John Fox wrote:

> 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

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon Jan 08 01:50:33 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 - 00:31:14 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.