find the creation date of a csv file in r

To find the creation date of a csv file in R, you can use the function file.info() to retrieve the metadata of the file, including its creation date. Here's an example:

main.r
# Set the path of the csv file
file_path <- "path/to/your/csv/file.csv"

# Retrieve the metadata of the file
file_info <- file.info(file_path)

# Extract the creation date
creation_date <- file_info$ctime

# Convert it to a human-readable format
creation_date_formatted <- format(as.POSIXct(creation_date, origin = "1970-01-01"), "%Y-%m-%d %H:%M:%S")

# Print the result
print(paste("The creation date of the csv file is:", creation_date_formatted))
450 chars
15 lines

In this example, file.info() takes the path of the csv file as an argument and returns a named list that includes various metadata of the file, such as its size, access time, modification time, etc. We use the ctime element of the list, which represents the inode change time of the file and is the closest we can get to the creation time of the file in Unix-like systems.

We then convert the ctime value to a POSIXct object using as.POSIXct(), with the origin set to "1970-01-01", which is the epoch time commonly used in Unix systems. We format the POSIXct object into a human-readable date and time string using format() and print the result.

Note that the format of the date and time string can be changed to match your preferred format.

gistlibby LogSnag