I'd like to control my namespace thoroughly, separated by task. Is there a way, in R session, to introduce namespaces for tasks dynamically and switch them as needed? Or, is there a combination of load/save workspace steps which can facilitate this? Cheers, Alexy
You could have an environment for each task and place your objects for each task in its environment. Note that this is getting close to object oriented ideas where each enviroment/task is an object containing your R variables and methods and the proto package can be used to facilitate that: library(proto) task1 <- proto(var = 0, addx = function(this, x) this$var <- this$var + x) task1$var # 0 task1$addx(3) task1$var # 3 On Thu, Oct 2, 2008 at 11:03 AM, Alexy Khrabrov <deliverable at gmail.com> wrote:> I'd like to control my namespace thoroughly, separated by task. Is there a > way, in R session, to introduce namespaces for tasks dynamically and switch > them as needed? Or, is there a combination of load/save workspace steps > which can facilitate this? > > Cheers, > Alexy > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
What you mean is probably that you can have different workspaces. A Workspace is associated to the current R session and is saved/loaded in the directory from which R is started. Note that Namespaces (for packages) in R have a different meaning. Best, Uwe Ligges Alexy Khrabrov wrote:> I'd like to control my namespace thoroughly, separated by task. Is > there a way, in R session, to introduce namespaces for tasks dynamically > and switch them as needed? Or, is there a combination of load/save > workspace steps which can facilitate this? > > Cheers, > Alexy > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 02/10/2008 11:03 AM, Alexy Khrabrov wrote:> I'd like to control my namespace thoroughly, separated by task. Is > there a way, in R session, to introduce namespaces for tasks > dynamically and switch them as needed? Or, is there a combination of > load/save workspace steps which can facilitate this?"namespace" has a specific meaning in R associated with packages, but I think you are using it more generally. The search() list in R controls what is visible when executing commands in the console. You can attach and detach things from there to control visibility. You can also control the environment of a function, so that searches for non-local variables go where you want. Duncan Murdoch
Here is what I do: I have a different folder/directory for each of my different projects, then I start a new R session for each project that I am working on. If you start R with the folder/directory as the current working directory then the workspace for that project is loaded (and the script files in that directory show up when I want to load them). This means that I often have multiple copies of R running at the same time (which works fine), and switching between the projects just means switching which R window I am in. The workspace saving between sessions pretty much takes care of itself (but still keep the script files to recreate data if needed). If you are using windows, then the website: http://research.stowers-institute.org/efg/R/TechNote/WindowsExplorerWorkingDirectory/index.htm shows a way to set up windows so that you can run R from a given folder using a right click. I also have the line: utils::setWindowTitle(getwd()) in my .Rprofile so that the working folder name shows up in the window title. Not exactly what you asked for, but it works well for me. Hope it helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Alexy Khrabrov > Sent: Thursday, October 02, 2008 9:03 AM > To: r-help at stat.math.ethz.ch > Subject: [R] namespaces > > I'd like to control my namespace thoroughly, separated by task. Is > there a way, in R session, to introduce namespaces for tasks > dynamically and switch them as needed? Or, is there a combination of > load/save workspace steps which can facilitate this? > > Cheers, > Alexy > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.