Create an empty list called "result" before you run the loop.  Then store 
the results of the loop in the list.  For example:

result <- vector(mode="list", length=1000)
for(i in 1:1000){ 
        result[[i]] <- try(harvest(i))
        }

Jean



mdvaan <mathijsdev...@gmail.com> wrote on 11/27/2012 12:09:38 AM:
> 
> Hi,
> 
> I have written a function "harvest" and I would like to run the function 
for
> each value in a vector c(1:1000). The function returns 4 list objects
> (obj_1, obj_3, obj_3, obj_4) using the following code at the end of the
> function: return(list(obj_1 = obj_1, obj_2 = obj_2, obj_3 = obj_3, obj_4 
=
> obj_4)).
> 
> Since I am connecting with the web in the function and the connection
> sometimes fails causing errors to occur, I invoke the function as 
follows:
> 
> for(i in 1:1000){
>   result <- try(harvest(i));
>   if(class(result) == "try-error") next;
>   }
> 
> Everything works well accept for the fact that "result" only stores 
obj_1, 
> obj_2, obj_3,  obj_4 for the last i in the loop. How do I store obj_1, 
> obj_2, obj_3,  obj_4 for the first i in the first 4 elements of result, 
the
> objects for the second i in the next 4 elements, etc?
> 
> Thank you very much. 

        [[alternative HTML version deleted]]

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

Reply via email to