Skip to content

how to get old type.convert() numeric behavior?

1 message · Andrew Piskorski

#
Regarding this change:
How do I get the old behavior where type.convert() automatically
converts to numeric if suitable, regardless of whether or not the
string has more than 17 digits of accuracy?

Sure, I could first pass every single column of data through a kludgy
checking function like my.can.be.numeric() below, and then set
colClasses to "numeric" or not based on that, but is there a better
way?


my.can.be.numeric <- function(xx) { 
   old.warn <- options(warn = -1) 
   on.exit(options(old.warn)) 
   (!is.na(as.numeric(xx))) 
} 

Example of the changed behavior in R 3.1.0 vs. earlier versions, both
with options("digits"=10) set:
  
# R version 3.1.0 Patched (2014-04-15 r65398) -- "Spring Dance" 
# Platform: x86_64-unknown-linux-gnu/x86_64 (64-bit)
[1] 0.01234568
[1] "0.012345678901234567" 

# R version 3.0.2 Patched (2013-10-23 r64103) -- "Frisbee Sailing" 
# Platform: x86_64-unknown-linux-gnu/x86_64 (64-bit)
[1] 0.01234568
[1] 0.01234568