Pregunta

UPDATE

The following bash commandline seems to show it is not a R problem (play with the sleep to see it will only update at 0.43 and 0.93 past each second). (So I've changed the question tags.)

touch tmp.txt;stat tmp.txt;sleep 0.5;touch tmp.txt;stat tmp.txt

However I see "Modify: 2013-06-20 14:28:36.938579054", not "Modify: 2013-06-20 14:28:36", suggesting that my linux kernel is compiled and configured for nanosecond accuracy. So, I'm still a bit stumped why it appears to be an awful long away from nanonsecond accuracy!


The below script isolates a problem I discovered in a real script. I'm saving data to the same file, repeatedly. It appears that file.info$mtime only updates twice a second. When I use the 0.05s sleep the problem is quite distinct: file.info does not update 87 or 88 times out of 100. If I increase the sleep to 0.5s it works perfectly (bad==0). If I reduce the sleep to 0.4s it goes wrong 14 times out of 100.

My question is: is this an R bug, or something to do with the O.S.? Or am I doing something wrong, or making a bad assumption?

I'm using R 3.0.1, on Ubuntu 10.04.

BTW, I notice when running the below that the mtime's are always ending at either .936 or .436 (or something very close to those). Never at 0.250, or 0.800, or 0.950, etc.

One more possibly useful data point: I tried doing file.remove each time before calling save. It made no difference.

fname="tmp.rdata"
options(digits.secs = 3)

data=runif(100)
save(list=c("data"),file=fname)
info=file.info(fname)

ix=0;bad=0

while(ix<100){
    Sys.sleep(0.05)
    data=runif(100)
    current=Sys.time()
    save(list=c("data"),file=fname)
    info2=file.info(fname)
    if(info2$mtime<=info$mtime){bad=bad+1;cat("****************\n")}
    print(current);print(rbind(info,info2))
    ix=ix+1;info=info2
    }
cat("bad=",bad,"\n")

Here is the output of stat -c "%y" * |sort, for the files from the past two months. So it appears the dates can be anywhere in the second. Yet, for files saved at around the same time they all seem to have the same two values?!

2013-04-16 14:41:50.331227602
2013-04-19 20:52:50.238225648
2013-04-30 10:34:43.896278930
2013-05-02 08:36:39.360523004
2013-05-02 08:46:07.848039045
2013-05-07 17:10:19.372043866
2013-05-07 19:12:00.369502114
2013-05-07 19:19:11.370293101
2013-05-07 22:14:39.744755951
2013-05-07 22:14:58.242163170
2013-05-24 12:21:06.231306593
2013-06-06 15:14:40.174142594
2013-06-10 11:16:31.958667081
2013-06-10 11:18:29.958090098
2013-06-10 11:34:16.961026520
2013-06-12 10:44:12.825080955
2013-06-14 12:50:49.531729270
2013-06-17 11:05:23.792289000
2013-06-18 11:44:40.347221361
2013-06-19 13:10:46.590013564
2013-06-20 11:52:16.436423344
2013-06-20 11:52:24.437938646
2013-06-20 11:52:24.437938646
2013-06-20 13:17:16.436666359
2013-06-20 13:20:50.928713629
2013-06-20 14:28:36.938579054
¿Fue útil?

Solución

If you are getting updates twice per second you are actually doing pretty good. An excerpt from page 227 of the R-project reference regarding file.info:

What is meant by the three file times depends on the OS and file system. On Windows native file systems ctime is the file creation time (something which is not recorded on most Unix-alike file systems). What is meant by ‘file access’ and hence the ‘last access time’ is system-dependent.

The times are reported to an accuracy of seconds, and perhaps more on some systems. However, many file systems only record times in seconds, and some (e.g. modification time on FAT systems) are recorded in increments of 2 or more seconds

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top