I have a script that contains multiple blocks with lines that look like this...
#Read data for X
DataX = read.delim(file = 'XRecords.txt',
col.names = XFields[,'FieldName'])
print('Data X read')
#Convert fields that should be numeric into numeric so they can summed
DataX[,NumFieldNames] = as.numeric(as.character(XData[,NumFieldNames]))
print('Data X scrubbed')
When I source the script I get an output like this...
[1] "Data X read"
[1] "Data X scrubbed"
[1] "Data Y read"
[1] "Data Y scrubbed"
Warning message:
In eval(expr, envir, enclos) : NAs introduced by coercion
Based on that output, I reload data Y and began looking for records where the string to numeric conversion failed. After a couple hours of frustration, I realized that data X was actually the one that had type conversion errors.
It looks like what's happening is that an warning is raised, but it does not display on the console until the script finishes. Is there a way to make warnings output to the console as soon as they are raised? I tried flush.console(), but it doesn't seem to work for warnings.
I'd prefer not to have load any additional packages onto my system if it can be avoided. I'm using this for work, and I had to jump through a few hoops just to get the CRAN distribution installed on my computer.
Thank you. I appreciate the help.