Re: [R] save intermediate result

2007-05-05 Thread Joerg van den Hoff
On Fri, May 04, 2007 at 04:55:36PM -0400, Weiwei Shi wrote:
 sorry for my English, staying in US over 7 years makes me think I were
 ok, now :(
 
 anyway, here is an example and why I need that:
 
 suppose I have a function like the following:
 
 f1 - function(){
 line1 - f2() # assume this line takes very long time, like more than 30 min
 # then I need to save line1 as an object into workspace b/c
 # the following lines after this might have some bugs
 # currently I use
 save(line1, file=line1.robj)
 # but I am thinking if there is anothe way, like enviroment, instead
 of save it into a file
 
 # codes as followed might have some bugs
 # blabla...
 }

yes, that's what I thought you meant. so use

line1 - f2()

i.e. the assignment operator `-' instead of `-'. after f2() is
finished, the object `line1' is available from the R prompt, i.e.
visible in the workspace (for details, cf. `help(-)').

 
 if some codes as followed have bugs, my f1 function cannot return
 anything, which means I have to re-run the time-consuming line again.

you probably should debug it using some dummy data instead of the f2()
call...

 
 thanks,
 
 Weiwei
 
 On 5/4/07, Joerg van den Hoff [EMAIL PROTECTED] wrote:
 On Fri, May 04, 2007 at 03:45:10PM -0400, Weiwei Shi wrote:
  hi,
 
  is there a way to save a R object into workspace instead of into a
  file during a running of function?
 
 
 if I understand the question correctly you want the 'super-assignment'
 operator `-' as in
 
 -cut---
 R f - function(x) y - 2*x
 R f(1)
 R y
 [1] 2
 R f(10)
 R y
 [1] 20
 -cut---
 
 i.e. y is assigned a value in the 'workspace'. be careful, though, with
 this kind of assignment. why not return the object you are interested
 in as a list component together with other results when the function
 call finishes?
 
 
 
 
 -- 
 Weiwei Shi, Ph.D
 Research Scientist
 GeneGO, Inc.
 
 Did you always know?
 No, I did not. But I believed...
 ---Matrix III

__
R-help@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.


Re: [R] save intermediate result

2007-05-05 Thread jim holtman
Break your long running function into two parts.  The first will be
the long running part and it can return a value that you can pass to
the second part.  If the second part fails, you still have the
original value that was returned.

f1.1 - function(){
line1 - f2()
return(line1)
}

f1.2 - function(line1){
 rest of the original f1
}

origData - f1.1()
nextData - f1.2(origData)


On 5/4/07, Weiwei Shi [EMAIL PROTECTED] wrote:
 sorry for my English, staying in US over 7 years makes me think I were
 ok, now :(

 anyway, here is an example and why I need that:

 suppose I have a function like the following:

 f1 - function(){
  line1 - f2() # assume this line takes very long time, like more than 30 min
  # then I need to save line1 as an object into workspace b/c
  # the following lines after this might have some bugs
  # currently I use
  save(line1, file=line1.robj)
  # but I am thinking if there is anothe way, like enviroment, instead
 of save it into a file

  # codes as followed might have some bugs
  # blabla...
 }

 if some codes as followed have bugs, my f1 function cannot return
 anything, which means I have to re-run the time-consuming line again.

 thanks,

 Weiwei

 On 5/4/07, Joerg van den Hoff [EMAIL PROTECTED] wrote:
  On Fri, May 04, 2007 at 03:45:10PM -0400, Weiwei Shi wrote:
   hi,
  
   is there a way to save a R object into workspace instead of into a
   file during a running of function?
  
 
  if I understand the question correctly you want the 'super-assignment'
  operator `-' as in
 
  -cut---
  R f - function(x) y - 2*x
  R f(1)
  R y
  [1] 2
  R f(10)
  R y
  [1] 20
  -cut---
 
  i.e. y is assigned a value in the 'workspace'. be careful, though, with
  this kind of assignment. why not return the object you are interested
  in as a list component together with other results when the function
  call finishes?
 
 


 --
 Weiwei Shi, Ph.D
 Research Scientist
 GeneGO, Inc.

 Did you always know?
 No, I did not. But I believed...
 ---Matrix III

 __
 R-help@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.



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@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.


[R] save intermediate result

2007-05-04 Thread Weiwei Shi
hi,

is there a way to save a R object into workspace instead of into a
file during a running of function?

thanks,

-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

Did you always know?
No, I did not. But I believed...
---Matrix III

__
R-help@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.


Re: [R] save intermediate result

2007-05-04 Thread Joerg van den Hoff
On Fri, May 04, 2007 at 03:45:10PM -0400, Weiwei Shi wrote:
 hi,
 
 is there a way to save a R object into workspace instead of into a
 file during a running of function?
 

if I understand the question correctly you want the 'super-assignment'
operator `-' as in

-cut---
R f - function(x) y - 2*x
R f(1)
R y
[1] 2
R f(10)
R y
[1] 20
-cut---

i.e. y is assigned a value in the 'workspace'. be careful, though, with
this kind of assignment. why not return the object you are interested
in as a list component together with other results when the function
call finishes?

__
R-help@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.


Re: [R] save intermediate result

2007-05-04 Thread Weiwei Shi
sorry for my English, staying in US over 7 years makes me think I were
ok, now :(

anyway, here is an example and why I need that:

suppose I have a function like the following:

f1 - function(){
 line1 - f2() # assume this line takes very long time, like more than 30 min
 # then I need to save line1 as an object into workspace b/c
 # the following lines after this might have some bugs
 # currently I use
 save(line1, file=line1.robj)
 # but I am thinking if there is anothe way, like enviroment, instead
of save it into a file

 # codes as followed might have some bugs
 # blabla...
}

if some codes as followed have bugs, my f1 function cannot return
anything, which means I have to re-run the time-consuming line again.

thanks,

Weiwei

On 5/4/07, Joerg van den Hoff [EMAIL PROTECTED] wrote:
 On Fri, May 04, 2007 at 03:45:10PM -0400, Weiwei Shi wrote:
  hi,
 
  is there a way to save a R object into workspace instead of into a
  file during a running of function?
 

 if I understand the question correctly you want the 'super-assignment'
 operator `-' as in

 -cut---
 R f - function(x) y - 2*x
 R f(1)
 R y
 [1] 2
 R f(10)
 R y
 [1] 20
 -cut---

 i.e. y is assigned a value in the 'workspace'. be careful, though, with
 this kind of assignment. why not return the object you are interested
 in as a list component together with other results when the function
 call finishes?




-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

Did you always know?
No, I did not. But I believed...
---Matrix III

__
R-help@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.