how to debug errors like: "dim(x) must have a positive length" with caret
<p>I'm running a predict over a fit similar to what is found in the caret guide:</p>

<p><a href="http://topepo.github.io/caret/measuring-performance.html" rel="nofollow noreferrer">Caret Measuring Performance</a></p>

<pre><code>predictions &lt;-  predict(caretfit, testing, type = "prob")
</code></pre>

<p>But I get the error:</p>

<pre><code>Error in apply(x, 1, paste, collapse = ",") : 
dim(X) must have a positive length
</code></pre>

<p>I would like to know 1) the general way to diagnose these errors that are the result of bad inputs into functions like this or 2) why my code is failing.</p>

<p>1)
So looking at the error It's something to do with 'X'.  Which argument is x? Obviously the first one in 'apply', but which argument in predict is eventually passed to apply?  Looking at traceback():</p>

<pre><code>10: stop("dim(X) must have a positive length")
9: apply(x, 1, paste, collapse = ",")
8: paste(apply(x, 1, paste, collapse = ","), collapse = "\n")
7: makeDataFile(x = newdata, y = NULL)
6: predict.C5.0(modelFit, newdata, type = "prob")
5: predict(modelFit, newdata, type = "prob") at C5.0.R#59
4: method$prob(modelFit = modelFit, newdata = newdata, submodels = param)
3: probFunction(method = object$modelInfo, modelFit = object$finalModel, 
   newdata = newdata, preProc = object$preProcess)
2: predict.train(caretfit, testing, type = "prob")
1: predict(caretfit, testing, type = "prob")
</code></pre>

<p>Now, this problem would be easy to solve if I could follow the code through and understand the problem as opposed to these general errors.  I can trace the code using this traceback to the code at C5.0.R#59.  (It looks like there's no way to get line numbers on every  trace?)  I can follow this code as far as this line 59 and then (I think) the predict function on line 44:</p>

<p><a href="https://github.com/topepo/caret/blob/36f8216a1f18e17021adfd17ebdffa8e9f058949/models/files/C5.0.R" rel="nofollow noreferrer">Github Caret C5.0 source</a></p>

<p>But after this I'm not sure where the logic flows.  I don't see 'makeDataFile' anywhere in the caret source or, if it's in another package, how it got there.  I've also tried Rstudio debugging, debug() and browser(). None provide the stacktrace I would expect from other languages.  Any suggestion on how to follow the code when you don't know what an error msg means?</p>

<p>2)  As for my particular inputs, 'caretfit' is simply the result of a caret fit and the testing data is 3million rows by 59 columns:</p>

<pre><code>fitcontrol &lt;- trainControl(method = "repeatedcv",
                       number = 10,
                       repeats = 1,
                       classProbs = TRUE,
                       summaryFunction = custom.summary,
                       allowParallel = TRUE)


fml &lt;- as.formula(paste("OUTVAR ~",paste(colnames(training[,1:(ncol(training)-2)]),collapse="+")))
caretfit &lt;- train(fml,
             data = training[1:200000,],
             method = "C5.0",
             trControl = fitcontrol,
             verbose = FALSE,
             na.action = na.pass)
</code></pre>