Skip to content

Instantly share code, notes, and snippets.

@wch
Last active November 9, 2021 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wch/d2c6cb9051783d98872910d4bb21573d to your computer and use it in GitHub Desktop.
Save wch/d2c6cb9051783d98872910d4bb21573d to your computer and use it in GitHub Desktop.
C function to get mtime of a file, from R
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