I have a few hundred files of formatted data. Unfortunately most of them end with a spurious CONTROL-Z. I want to rewrite the files without the spurious character. Here's what I've come up with so far, but my code is unsafe because it assumes without justification that the last row of df contains a control character (and some NAs to fill up the record).
options(warn=-1) #turn off irritating warning from read.table() df<-read.table(file=filename) df.new<-df[1:nrow(df)-1,] write.table(df.new,file=filename.new, quote=F) Before defining df.new, I want to check that the last line really does contain a control character. I've tried various methods, but none of them work. I have been wondering if I should use a function (scan?) that reads in the file line by line and checks each line for control characters, but I don't know how to do this either. Thanks for any help David -- View this message in context: http://www.nabble.com/eliminating-control-characters-from-formatted-data-files-tp21847583p21847583.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.