r - Specifying column classes in read.csv.sql -


when reading in .csv using read.csv.sql sqldf package, possible specify column classes rather having function guess @ them contents?

supposing have .csv file large read using base read.csv, column know character class contains numeric values. no positive value of nrows guaranteed catch non-numeric values , assign correct class, , nrows=-1 load entire colum vecotr r, avoiding doing reason i'm using read.csv.sql.

this example sqldf home page.

library(sqldf)  # example example 8a - file.format attribute on file.object  numstr <- as.character(1:100) df <- data.frame(a = c(numstr, "hello")) write.table(df, file = "~/tmp.csv", quote = false, sep = ",") ff <- file("~/tmp.csv")  attr(ff, "file.format") <- list(colclasses = c(a = "character"))  tail(sqldf("select * ff"))   # example 8b - using file.format argument  numstr <- as.character(1:100) df <- data.frame(a = c(numstr, "hello")) write.table(df, file = "~/tmp.csv", quote = false, sep = ",") ff <- file("~/tmp.csv")  tail(sqldf("select * ff",  file.format = list(colclasses = c(a = "character")))) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -