touchFile

0th

Percentile

Updates the timestamp of a file

Updates the timestamp of a file. Currently, it is only possible to change the timestamp specifying when the file was last modified, and time can only be set to the current time.

Keywords
file, programming, IO
Usage
# S3 method for default
touchFile(pathname, ...)
Arguments
pathname

A character vector specifying files to be updated.

...

Not used.

Value

Returns (invisibly) a vector of the old timestamps.

References

[1] R-devel mailing list thread Unix-like touch to update modification timestamp of file?, started on 2008-02-26. http://stat.ethz.ch/pipermail/r-devel/2008-February/048542.html

See Also

Internally, Sys.setFileTime() (iff available) and file.info() are utilized.

Aliases
  • touchFile.default
  • touchFile
Examples
# NOT RUN {
# 1. Create a file
pathname <- tempfile()
cat(file=pathname, "Hello world!")
md5a <- digest::digest(pathname, file=TRUE)

# 2. Current time stamp
ta <- file.info(pathname)$mtime
print(ta)

# 3. Update time stamp
Sys.sleep(1.2)
touchFile(pathname)
tb <- file.info(pathname)$mtime
print(tb)

# 4. Verify that the timestamp got updated
stopifnot(tb > ta)

# 5. Verify that the contents did not change
md5b <- digest::digest(pathname, file=TRUE)
stopifnot(identical(md5a, md5b))
# }
Documentation reproduced from package R.utils, version 2.8.0, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.