[R] Redefining the for loop

From: <ast_shopping_at_gmx.de>
Date: Sun, 22 Jun 2008 21:21:43 +0200


I have the following problem:

I want to redefine the for loop (or define a similar statement) to change its behavior under some circumstances. So, I would like sthg. like

"For" = function ( var, vec, statement ) {  

  if ( ... ) {
    /* my implementation of for */

  else {
    /* call R's for loop */


I tried to manipulate the elements of the list one gets by

e = quote( for ( i in (1:10) ) print("*") )

That means, storing the variable in e[[2]] (my trials didn't work), and the statement in e[[4]], but I failed.

How can one do this in R? It would be best, if I could redefine "for" directly, so that one can use the same syntax, i.e., with the statement after the function call.

Can somebody help me?




Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 22 Jun 2008 - 19:27:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 22 Jun 2008 - 19:30:49 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive