Skip to content
Prev 305816 / 398506 Next

Trap an error from a function

David,
Thank you. I will study your code so I can understand your suggestion. 
Thanks,
John

 
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> David Winsemius <dwinsemius at comcast.net> 9/18/2012 8:35 PM >>>
On Sep 18, 2012, at 5:10 PM, John Sorkin wrote:

            
?conditions   #### has lots of fancy stuff
# But I use just plain old `try`

test=-10:10
sapply(test, function(x)  if( "try-error" %in% 
                     class( try( test[test[x:1]] ) ) ){
                     2}else{0} )
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
Error in test[x:1] : only 0's may be mixed with negative subscripts
[1] 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0

You still get the messages but the code runs.