JRDew
JRDew

Reputation: 149

RStudio read Created or Modified Date of file into variable

I am using read.csv to import the data from my csv file. I would also like to load the Created or Modified Date of the file to a new column at the end of my newly imported table. How do I read the Created or Modified date of a file into a variable? Thanks

Upvotes: 1

Views: 2291

Answers (2)

Justin Dallmann
Justin Dallmann

Reputation: 1

Here is a tidyverse answer:

library(dplyr)

# function takes csv file names, reads named file 
# into a tibble with columns for last_modified and created.

read_date_csv <- function(file_name){
    read_csv(file_name) %>%
        mutate(last_modified = file.info(file_name)$mtime,
               created = file.info(file_name)$ctime)
}

Upvotes: 0

VincentP
VincentP

Reputation: 89

This function may work well:

read.tables <- function(file.names, ...) {require(plyr)
ldply(file.names, function(fn) data.frame(read.table(fn, ...), Filename=fn, date.extraction=date(file.info(fn)$mtime)))}

I simply modified the function given in this topic: how to read table multiple files into a single table in r

Upvotes: 1

Related Questions