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
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to