David,
This may be a case of "If all you have is a hammer, everything looks like a
nail".
If all you want to do is remove the last line if it contains a CONTROL-Z,
why
not use something like perl to process the files?
Murray M Cooper, Ph.D.
Richland Statistics
9800 N 24th St
Richland, MI, USA 49083
Mail: richs...@earthlink.net
----- Original Message -----
From: "David Epstein" <david.epst...@warwick.ac.uk>
To: <r-help@r-project.org>
Sent: Thursday, February 05, 2009 4:01 AM
Subject: [R] eliminating control characters from formatted data files
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.
______________________________________________
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.