[R] R 3.1 changes to type.convert causing strings where I used to get numeric

Bos, Roger roger.bos at rothschild.com
Wed Apr 30 22:20:46 CEST 2014

Dear R-help,

I recently upgraded to R 3.1 patched and code that ran fine previously and now giving a lot of errors because the data is coming in as strings instead of numeric.  I can fix my code to wrapping each item I want to use with as.numeric(), but that seems very inefficient.

I looked at the change list for R 3.1 and I see the first item is a change in type.convert() that seems to be causing me grief.  The suggestion is to use colClasses, but when I try to do so I get an error regarding the quotes again...

>       ann1  <- read.table(driveletter %+% "/snap/ann/snap_fyr_ann1_" %+% i %+% ".txt", header=TRUE, quote="", as.is=TRUE, colClasses='numeric')
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  scan() expected 'a real', got '"1033.7"'

Does anyone have any suggestions?


type.convert() (and hence by default read.table()) returns a character vector or factor when representing a numeric input as a double would lose accuracy. Similarly for complex inputs.
If a file contains numeric data with unrepresentable numbers of decimal places that are intended to be read as numeric, specify colClasses in read.table() to be"numeric".

This message is for the named person's use only. It may
contain confidential, proprietary or legally privileged
information. No right to confidential or privileged treatment
of this message is waived or lost by an error in transmission.
If you have received this message in error, please immediately
notify the sender by e-mail, delete the message and all
copies from your system and destroy any hard copies.  You must
not, directly or indirectly, use, disclose, distribute,
print or copy any part of this message if you are not
the intended recipient.

More information about the R-help mailing list