[R] how to import several files every day

Jim Lemon jim at bitwrit.com.au
Mon Apr 22 13:09:40 CEST 2013


On 04/22/2013 09:00 PM, Martin Lavoie wrote:
> Hi Jim
>
> actually I did not underscore my code. I just copied and pasted the
> original code you suggested.
>
> but here is what I have on my system (I tried with csv files if I would
> get a different result):
> #
> 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
>
> As you see filenames = all.filenames
>
Hi Martin,
I think this has something to do with your OS. I checked my original 
reply and there are no underscores in the filenames, so they must have 
been added by the OS on your end. I ran the above through my system just 
to make sure that the "./" path wasn't causing any trouble and:

 > 
all.filenames<-c("./GMReducedF.csv","./HLReducedF.csv","./MinardReducedF.csv",
+  "./Site1ReducedF.csv","./Site2ReducedF.csv")
 > old.filenames<-c("x","./GMReducedF.csv","./HLReducedF.csv",
+  "./MinardReducedF.csv")
 > filenames<-all.filenames[!(all.filenames %in% old.filenames)]
 > filenames
[1] "./Site1ReducedF.csv" "./Site2ReducedF.csv"

I think the above is what you want, but I can't do much about whatever 
is causing the problem on the Mac. Perhaps an Apple user on the list can 
help.

Jim



More information about the R-help mailing list