touchFile {R.utils}R Documentation

Updates the timestamp of a file

Description

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.

Usage

## Default S3 method:
touchFile(pathname, ...)

Arguments

pathname A character specifying the file to be updated.
... Not used.

Value

Returns (invisibly) the old timestamp.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

See Also

file.info().

Examples

# 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))

[Package R.utils version 1.1.7 Index]