touchFile: Updates the timestamp of a file

Description Usage Arguments Value Author(s) References See Also Examples

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

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

Arguments

pathname

A character vector specifying files to be updated.

...

Not used.

Value

Returns (invisibly) a vector of the old timestamps.

Author(s)

Henrik Bengtsson

References

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

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# 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))

Example output

Loading required package: R.oo
Loading required package: R.methodsS3
R.methodsS3 v1.7.1 (2016-02-15) successfully loaded. See ?R.methodsS3 for help.
R.oo v1.22.0 (2018-04-21) successfully loaded. See ?R.oo for help.

Attaching package: 'R.oo'

The following objects are masked from 'package:methods':

    getClasses, getMethods

The following objects are masked from 'package:base':

    attach, detach, gc, load, save

R.utils v2.8.0 successfully loaded. See ?R.utils for help.

Attaching package: 'R.utils'

The following object is masked from 'package:utils':

    timestamp

The following objects are masked from 'package:base':

    cat, commandArgs, getOption, inherits, isOpen, parse, warnings

[1] "2019-03-25 20:07:04 UTC"
[1] "2019-03-25 20:07:05 UTC"

R.utils documentation built on Sept. 26, 2021, 9:07 a.m.