where 1: eval(expr, envir, enclos)
where 2: eval(quote(browser()), envir = sys.frame(which))
where 3 at cities.R#13: function ()
{
if (.isMethodsDispatchOn()) {
tState <- tracingState(FALSE)
...
Okay, so the problem occurred inmind()rather thanimin()and in par-
ticular at line 13. It still could be the fault ofimin(), but for now, let’s deal
with the former.
NOTE There is another way we could have determined that the blowup occurred on line 13.
We would enter the debugger as before but probe the local variables. We could reason
that if the subscript bounds error had occurred at line 9, then the variablewminswould
not have been set, so querying it would give us an error message likeError: object
'wmins' not found.On the other hand, if the blowup occurred on line 13, evenj
would have been set.
Since the error occurred withd[i,j], let’s look at those variables:
Browse[1]> d
[,1] [,2] [,3]
[1,] 0 12 5
[2,] 12 0 8
[3,]580
Browse[1]> i
[1] 2
Browse[1]> j
[1] 12
This is indeed a problem—donly has three columns, yetj, a column
subscript, is 12.
Let’s look at the variable from which we gleanedj,wmins:
Browse[1]> wmins
[,1] [,2]
[1,] 2 1
[2,] 12 12
If you recall how the code was designed, columnkofwminsis supposed
to contain information about the minimum value in rowkofd. So here
wminsis saying that in the first row (k=1)ofd,(0,12,5), the minimum value
is 12, occurring at index 2. But it should be 5 at index 3. So, something went
wrong with this line:
wmins <- apply(dd[-n, ], 1, imin)
Debugging 297