[R] How to a handle an error in a loop

Farrel Buchinsky fjbuch at gmail.com
Tue May 9 00:57:16 CEST 2006


"Seth Falcon" <sfalcon at fhcrc.org> wrote in message 
news:m2bquaei4x.fsf at ziti.local...
> If you want to do more than one thing, you want to create an anonymous
> function.  Here's an example:
>
Thanks for the example. Between what you did and some reading that I did I 
have got a vague idea of how to use the {} curly brackets and how to create 
functions. It appears that the "function()" function together with the curly 
brackets allows one to put several command lines into one location. It 
allows one to overcome the problem of stuffing 3 lines into one spot as I 
had asked earlier.

I will confess that I have not tried your solution (although it appears to 
be very elegant and efficient). Instead, immediately after posting my 
questions, I persevered with my "for" loop that was able to print out a 
whole series of "works" but would print the number of the column that caused 
an error (see earlier post in this thread). I then rand the whole data frame 
through the loop. I then scrolled through the output buffer and noted which 
columns had a problem. There were about 15 or 20 columns. I simply named 
them in a c() function. From that point on it was "Heaven on Earth" from a 
statistical analysis point of view. I ran the lapply function with the tdt 
function in it and I was easily able to pass on the whole dataframe but 
exclude the columns that either did not have genotyping information in it or 
had information that I knew would cause an error.

I performed almost 6000 tdt tests serially and output all the information to 
a named object. In turn, that named object could be summarized and 
interrogated.
If anybody wants more information, then feel free to contact me.

My thoughts on R: incredibly powerful, incredibly flexible, very steep 
learning curve but thanks to people on this mailing list and thanks to David 
Clayton it was all doable. As I have become more proficient with R so I am 
better able to help others in my center. It is quite paradoxical that since 
R is open source there is no official technical support, yet when I needed 
help it was more rapid and more insightful then anything I have ever 
experienced with commercial software.

Farrel Buchinsky




More information about the R-help mailing list