[R] Traceback NA's to their first appearance
murdoch at stats.uwo.ca
Sun May 10 12:03:24 CEST 2009
On 10/05/2009 1:01 AM, Benjamin Leutner wrote:
> I've written a relatively complex interconnected population model in R.
> When changing a certain parameter, the outputs end up containing NA's.
> I would like to find out, in which step the model (in form of a loop)
> starts to produce NA's. Does anyone know how to achieve this?
> Since it does not give an error I can't use the traceback() function.
There's no automatic way that I know of, but modifications to your code
are relatively easy. any(is.na(x)) will give TRUE if there are any NAs
in x. So adding the line
if (any(is.na(x))) browser()
to your code will drop to the browser if this is ever detected; you can
then debug your code to work out what happened.
More information about the R-help