Dear R-Helper,
I want to know how I get a list work which I saved in RData file. For
example,
> test.xy <- function(x,y) {
+ xy <- x+y
+ xy
+ }
>
> xyadd <- test.xy(x=2, y=3)
> xyadd
[1] 5
> x1 <- c(2,43,60,8)
> y1 <- c(91,7,5,30)
>
> xyadd1 <- test.xy(x=x1, y=y1)
> xyadd1
[1] 93 50 65 38
> save(list = ls(all=TRUE), file = "testxy.RData")
> rm(list=ls(all=TRUE))
> load("C:/R/useR/testxy.RData")
> ls()
[1] "test.xy" "x1" "xyadd"
"xyadd1" "y1"
>
> ls.str(pat="xyadd")
xyadd : num 5
xyadd1 : num [1:4] 93 50 65 38
>
When I run, I know the result like above
> xyadd
[1] 5
> xyadd1
[1] 93 50 65 38
>
what I want to know, is there any function to make the result like:
> xyadd
test.xy(x=2, y=3)
and
> xyadd1
test.xy(x=x1, y=y1)
Best,
Xiyan Lon
On Mon, 15 Aug 2005, Xiyan Lon wrote:> Dear R-Helper,(There are quite a few of us.)> I want to know how I get a list work which I saved in RData file. For > example,I don't understand that at all, but it looks as if you want to save an unevaluated call, in which case see ?quote and use something like xyadd <- quote(test.xy(x=2, y=3)) load and saving has nothing to do with this: it doesn't change the meaning of objects in the workspace.> > test.xy <- function(x,y) { > + xy <- x+y > + xy > + } > > > > xyadd <- test.xy(x=2, y=3) > > xyadd > [1] 5 > > x1 <- c(2,43,60,8) > > y1 <- c(91,7,5,30) > > > > xyadd1 <- test.xy(x=x1, y=y1) > > xyadd1 > [1] 93 50 65 38 > > save(list = ls(all=TRUE), file = "testxy.RData") > > rm(list=ls(all=TRUE)) > > load("C:/R/useR/testxy.RData") > > ls() > [1] "test.xy" "x1" "xyadd" "xyadd1" "y1" > > > > ls.str(pat="xyadd") > xyadd : num 5 > xyadd1 : num [1:4] 93 50 65 38 > > > > When I run, I know the result like above > > xyadd > [1] 5 > > xyadd1 > [1] 93 50 65 38 > > > what I want to know, is there any function to make the result like: > > > xyadd > > test.xy(x=2, y=3) > > and > > > xyadd1 > > test.xy(x=x1, y=y1)-- Brian D. Ripley, ripley at 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
If you want to keep track of the function call that produced an object, usually you need to do that inside the function that's being called, e.g.,> test.xy <- function(x,y) {+ xy <- x+y + attr(xy, "Call") <- match.call() + xy + }> xyadd <- test.xy(x=2, y=3) > xyadd[1] 5 attr(,"Call") test.xy(x = 2, y = 3)> str(xyadd)atomic [1:1] 5 - attr(*, "Call")= language test.xy(x = 2, y = 3) Andy> From: Xiyan Lon > > Dear R-Helper, > I want to know how I get a list work which I saved in RData > file. For > example, > > > test.xy <- function(x,y) { > + xy <- x+y > + xy > + } > > > > xyadd <- test.xy(x=2, y=3) > > xyadd > [1] 5 > > x1 <- c(2,43,60,8) > > y1 <- c(91,7,5,30) > > > > xyadd1 <- test.xy(x=x1, y=y1) > > xyadd1 > [1] 93 50 65 38 > > save(list = ls(all=TRUE), file = "testxy.RData") > > rm(list=ls(all=TRUE)) > > load("C:/R/useR/testxy.RData") > > ls() > [1] "test.xy" "x1" "xyadd" "xyadd1" "y1" > > > > ls.str(pat="xyadd") > xyadd : num 5 > xyadd1 : num [1:4] 93 50 65 38 > > > > When I run, I know the result like above > > xyadd > [1] 5 > > xyadd1 > [1] 93 50 65 38 > > > what I want to know, is there any function to make the result like: > > > xyadd > > test.xy(x=2, y=3) > > and > > > xyadd1 > > test.xy(x=x1, y=y1) > > Best, > Xiyan Lon > > ______________________________________________ > 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 > > >