Last active
November 9, 2021 19:20
-
-
Save wch/d2c6cb9051783d98872910d4bb21573d to your computer and use it in GitHub Desktop.
C function to get mtime of a file, from R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(inline) | |
get_mtime <- cfunction( | |
signature(filename = "character"), | |
includes = " | |
#include <time.h> | |
#include <sys/stat.h>", | |
body = ' | |
const char* path = CHAR(asChar(filename)); | |
struct stat attr; | |
stat(path, &attr); | |
return Rf_ScalarReal(attr.st_mtime); | |
' | |
) | |
mtime <- get_mtime("DESCRIPTION") | |
as.POSIXct(mtime, origin = "1970-01-01", tz = "UTC") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment