Examples for 'R.utils::touchFile.default'


Updates the timestamp of a file

Aliases: touchFile.default touchFile

Keywords: programming IO file

### ** 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)
[1] "2025-08-11 15:54:48 UTC"
# 3. Update time stamp
Sys.sleep(1.2)
touchFile(pathname)
tb <- file.info(pathname)$mtime
print(tb)
[1] "2025-08-11 15:54:49 UTC"
# 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 2.11.0 Index]