Skip to content

Traceback NA's to their first appearance

2 messages · Benjamin Leutner, Duncan Murdoch

#
Hello,

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.

Thank you very much in advance
Ben
#
On 10/05/2009 1:01 AM, Benjamin Leutner wrote:
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.

Duncan Murdoch