Update file modification time (tap)

How do I touch file (i.e. update its modification time without changing its contents) in R? I am looking for a cross-platform inline (or packaged) equivalent:

 system2("touch", file_name) 
+6
source share
2 answers

See ?Sys.setFileTime
In this case, Sys.setFileTime(path_to_file_or_directory, Sys.time()) will apparently do its job:

In Unix-like, it uses the "if it is available, otherwise" system call. In the POSIX file system, it sets both the last access and modification time.

On Windows, it uses the SetFileTime system call to set the last recording time. Some Windows file systems only record a resolution time of two seconds.

Although I'm not sure how to match "it uses a system call", if available, otherwise "utimes" with any meaningful expression.

+4
source

I found the implementation in R.utils package, it uses the same template as suggested by @thelatemail, but also offers vectorization and reserve for R <2.14 and invisibly returns the old timestamp:

 R.utils::touchFile(file_name) 

As usual, library(sos); ???touch library(sos); ???touch was invaluable for finding this.

+5
source

Source: https://habr.com/ru/post/988421/


All Articles