R what is wrong with my code to loop thru files in dir and do replace -
i try reuse old code 1 co-worker gave (and learn). read files in path .sql extension , replace , write them out under new name or save edited. after still don't have full name in , command can't find path, after testing point file directly , got error. i'm on windows machine.
path = "c:/workdir/alpha/" out.file<-"" file.names <- dir(path, pattern =".sql") for(i in 1:length(file.names)){ file <- read.table(file.names[i]) gsub( "merry christmas", "happy new year", file ) out.file <- rbind(out.file, file) write.table(out.file, file = c(file,"new") } so file.names shows xxx.sql without portion, command should take care of??
thanks m
there plenty of ways intend, i'm afraid won't able read .sql using read.table function. also, ideally, write.table should placed out of loop. if want keep inside, want add append = true.
path = "c:/workdir/alpha/" out.file<-"" file.names <- dir(path, pattern =".sql") for(i in 1:length(file.names)){ gsub( "merry christmas", "happy new year", file ) file <- read.table(file.names[i]) out.file <- rbind(out.file, file) } write.table(out.file, file = "yourbigfile.txt", row.names = false, qmethod = "double")
Comments
Post a Comment