0

I am running into an issue with a large R script (+900 lines) towards the end I am trying to read a csv file which has 42 rows not counting the header

when I execute the entire script, I generate an error when trying to loop over the data frame generated by the read file....

updateClsPnL <- read.csv(closed_PnL, header=T)

    for(i in 1:nrow(updateClsPnL)){

nrow()=42 however the actual data frame (updateClsPnL) has 41 rows not including header (the source file has 42 rows). This generates an error on the 42nd loop since data for that line is NA.

If I then manually highlight and run the remaining code, which includes the above portion, the script then works as expected (updateClsPnL has 42 rows)?!? Not sure why RStudio only has 41 rows (when 42 is expected) and the nrow() count still shows 42 even though the dataframe has 41...and why manually highlighting/running this portion generates the correct/expected functionality?!

I've tried pausing the script for 20 seconds right before this area where the error occurs, thinking that might help, but no luck.

Any ideas?

trock2000
  • 302
  • 4
  • 13
  • 1
    If the CSV is only 42 lines then you should be able to post it here. In fact maybe even create a small repo in R and post that too. Otherwise it is hard to get anywhere with the limited data you have provided here. – Mike Wise Oct 03 '15 at 15:00
  • We have no way of knowing what is wrong with your script without seeing it. Please try to isolate the part of your script that produces the error and post it here with the data (or simulated data that produce the same error). http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – scoa Oct 03 '15 at 16:06

0 Answers0