I am receiving the following error in R while processing HRMS data using xcms.
ms_data_peaks_refined <- refineChromPeaks(ms_data_peaks, param = mpp)
[===========>----------------------------------------------------------------------------------------------------------] 69/680 ( 10%) in 1hError in FUN(X[[i]], ...) : subscript out of bounds
There are three different ways to troubleshoot. You can run under the debugger, or wait until the error occurs and then do traceback() to get the error trace, or you can set options(error = recover) so you can drop into the function and try to figure out what's up.
The second method is the easiest to do, but it usually just gives you a hint and then you may need to run under the debugger anyway. The third method sometimes works, but it's sort of a pain - it gives you choices of where to start over, and it's never clear to me which one is the right one, and you can't really step through anything because you will hit the error again and it drops you back into the recover screen. This leaves us with the debugger. For a regular function you could simply do debug(refineChromPeaks) and then run the function again. But this function is S4, so you have to use trace instead.
To use trace, you need to specify the object(s) that the function will dispatch on. Generally speaking what you would do is this:
> showMethods(refineChromPeaks)
## this will show you all the methods for this function.
## you can then check the class of the objects you are using to see what you dispatch on
## let's assume you have an XCMSnExp and a CleanPeaksParam object
> trace(refineChromPeaks, browser, signature = c(object="XCMSnExp", param="CleanPeaksParam"))
> ms_data_peaks_refined <- refineChromPeaks(ms_data_peaks, param = mpp)
## now you will drop into the debugger for that function and can step through to identify where the error is