An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mac/attachments/20130425/02d88152/attachment.pl>
Problem importing several files every day
3 messages · Martin Lavoie, Ben Bond-Lamberty
Martin, It looks like you need to change one line slightly: filenames<-all.filenames[!(all.filenames %in% old.filenames$V1)] ...because you're reading old.filenames.tab into a data frame. I don't think this should be platform-dependent, but don't know for sure. Another option, simpler it seems to me, would be to move the files to a "already_processed" folder when you're done with them. Ben On Thu, Apr 25, 2013 at 6:21 AM, Martin Lavoie
<martin21skifond at gmail.com> wrote:
Hi All
I sent a question to the R-help list a few days ago. It was suggested that
my problem could be related to my OS.
I want to import several .dat files every day of the week from the same
folder.
My question was how can I import on day 2, day3, day4... the new files in
the folder but without importing the files already imported from the
previous days.
The code suggested by one the member was:
*# first set up a dummy file for the first run to avoid an error
system("echo xxx > old.filenames.tab")
# obviously don't do this again
all.filenames<-list.files(path="pathtofile", full.names=TRUE)
old.filenames<-read.table("old.filenames.tab")
filenames<-all.filenames[!(all.filenames %in% old.filenames)]
write.table(all.filenames,file="old.filenames.tab",row.names=FALSE)*
The member who suggested the code is using a PC and he gets the correct
answer obviously but on my Mac, I get the wrong output (see below), that
is all.filenames = filenames (which should be the difference between
all.filenames and old.filenames).
Any suggestions?
thank you
martin
setwd("~/Desktop/folder/")
system("echo xxx > old.filenames.tab")
all.filenames<-list.files(pattern="[.]csv", full.names=TRUE)
old.filenames<-read.table("old.filenames.tab")
filenames<-all.filenames[!(all.filenames %in% old.filenames)]
write.table(all.filenames,file="old.filenames.tab",row.names=FALSE)
#
all.filenames
[1] "./GMReducedF.csv" "./HLReducedF.csv" "./MinardReducedF.csv"
old.filenames
V1 1 xxx #
filenames
[1] "./GMReducedF.csv" "./HLReducedF.csv" "./MinardReducedF.csv" ##Now with a few more files in the folder and after running the same code above:
all.filenames
[1] "./GMReducedF.csv" "./HLReducedF.csv" "./MinardReducedF.csv" "./Site1ReducedF.csv" "./Site2ReducedF.csv" #
old.filenames
V1 1 x 2 ./GMReducedF.csv 3 ./HLReducedF.csv 4 ./MinardReducedF.csv #
filenames
[1] "./GMReducedF.csv" "./HLReducedF.csv" "./MinardReducedF.csv"
"./Site1ReducedF.csv" "./Site2ReducedF.csv"
sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mac/attachments/20130425/2ee5c9cc/attachment.pl>