I was recently using glmnet to do some classification work. It’s a great package and worked really well for me, but I kept getting some really frustrating errors:
> Error in lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : > NA/NaN/Inf in foreign function call (arg 5)
This also happened with elnet, mrelnet…
A quick search of the Internet suggested that it often happened when you pass in bad data. Well, since I had written the Java code to create the input data, I was pretty sure that the data was correctly formatted. How hard can it be to create a CSV file and then read it into a data frame in R?
Well, turns out that I didn’t flush the file or close it, and the garbage collector doesn’t do that for you. So, the file I wrote was incomplete and I hadn’t looked at the last few lines.
Lesson learned – always close your files 🙂