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

thank you
martin



On Mon, Apr 22, 2013 at 4:34 AM, Jim Lemon <jim@bitwrit.com.au> wrote:

> On 04/22/2013 10:14 AM, Martin Lavoie wrote:
>
>> Hi Jim
>>
>> thanks for the help. I think I understand all the steps you suggested. I
>> tried an example with your code but there is something not working I
>> think. See below.
>>
>> all.filenames<-list.files(__**path="pathtofile", full.names=TRUE) /#this
>> step works/
>> old.filenames<-read.table("__**old.filenames.tab") /#this step works/
>> filenames<-all.filenames[!(__**all.filenames %in% old.filenames)]/## I
>>
>> think the problem is here because all.filenames = filenames (also
>> checked with str()), so I import all the files (old and new files added
>> to my folder) each time I run the code./
>> write.table(all.filenames,__**file="old.filenames.tab",row._**
>> _names=FALSE)
>> /#this step works/
>>
>> Any suggestion?
>>
>
> Hi Martin,
> This is what I get on my system:
>
> > all.filenames<-list.files(**pattern="[.]csv")
> > all.filenames
>  [1] "abc.csv"              "codseq.csv"           "eyeguess.csv"
>  [4] "eyeresults.csv"       "eyes_data.csv"        "fmsdf.csv"
>  [7] "obsnodecol5.csv"      "old.filenames.csv"    "Porzio.csv"
> [10] "rg_test.csv"          "water40.csv"          "water_content_40.csv"
> # 12 files with a .csv extension
> # create a new file with a .csv extension
> > system("touch fntest.csv")
> # I skipped the writing and reading, but this seems okay for you
> > old.filenames<-all.filenames
> # now get the new listing with the new file
> > all.filenames<-list.files(**pattern="[.]csv")
> > all.filenames
>  [1] "abc.csv"              "codseq.csv"           "eyeguess.csv"
>  [4] "eyeresults.csv"       "eyes_data.csv"        "fmsdf.csv"
>  [7] "fntest.csv"           "obsnodecol5.csv"      "old.filenames.csv"
> [10] "Porzio.csv"           "rg_test.csv"          "water40.csv"
> [13] "water_content_40.csv"
> # now there are 13 files with a .csv extension
>
> > filenames<-all.filenames[!(**all.filenames %in% old.filenames)]
> # only the new file is now in filenames
> > filenames
> [1] "fntest.csv"
>
> Are you sure that you want those underscores in your code? I don't think
> that "__old.filenames" and "old.filenames" will give you the same file.
>
> Jim
>

	[[alternative HTML version deleted]]

