Dear Listers: For example, if I have a .R source file which has more than one function, and I want to just load only one of the functions, how could I do that? (removing the rest after sourcing is not what I intend b/c in my workspace, I might have some of the rest and I don't want to change my workspace: i.e., I only change my workspace by adding one function from a R source file). Thanks, -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. "Did you always know?" "No, I did not. But I believed..." ---Matrix III
One way to do it would be to surround the function(s) you don't want sourced, like this: if (FALSE) { ## function definition here } But you might find it easier to just put each function in its own file. At 9:54 AM -0400 6/18/07, Weiwei Shi wrote:>Dear Listers: > >For example, if I have a .R source file which has more than one >function, and I want to just load only one of the functions, how could >I do that? (removing the rest after sourcing is not what I intend b/c >in my workspace, I might have some of the rest and I don't want to >change my workspace: i.e., I only change my workspace by adding one >function from a R source file). > >Thanks, > >-- >Weiwei Shi, Ph.D >Research Scientist >GeneGO, Inc. > >"Did you always know?" >"No, I did not. But I believed..." >---Matrix III > >______________________________________________ >R-help at stat.math.ethz.ch 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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA
This loads all the functions into an anonymous environment defined by local and then exports f to the global environment. f <- local({ source("/a.R", local = TRUE) environment(f) <- .GlobalEnv f }) On 6/18/07, Weiwei Shi <helprhelp at gmail.com> wrote:> Dear Listers: > > For example, if I have a .R source file which has more than one > function, and I want to just load only one of the functions, how could > I do that? (removing the rest after sourcing is not what I intend b/c > in my workspace, I might have some of the rest and I don't want to > change my workspace: i.e., I only change my workspace by adding one > function from a R source file). > > Thanks, > > -- > Weiwei Shi, Ph.D > Research Scientist > GeneGO, Inc. > > "Did you always know?" > "No, I did not. But I believed..." > ---Matrix III > > ______________________________________________ > R-help at stat.math.ethz.ch 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 6/18/2007 9:54 AM, Weiwei Shi wrote:> Dear Listers: > > For example, if I have a .R source file which has more than one > function, and I want to just load only one of the functions, how could > I do that? (removing the rest after sourcing is not what I intend b/c > in my workspace, I might have some of the rest and I don't want to > change my workspace: i.e., I only change my workspace by adding one > function from a R source file).In Windows, open the file in an editor, copy (e.g. by highlighting it and hitting Ctrl-C) the part you want to source to the clipboard, and then in R enter source("clipboard"), or just paste the selected text. I think source("clipboard") is Windows-specific, but other platforms support copy and paste in their own ways. Duncan Murdoch