View source: R/special-attributes.R
fread_plus_date | R Documentation |
Takes a file name, reads it with data.table::fread
, and
sets an attribute called lb.date
with a date extracted
from the file name.
fread_plus_date(fname, allow.fallback.date = TRUE, ...)
fname |
The file name to read |
allow.fallback.date |
A logical indicating whether, if no
matching file name with a date is found,
to use today's date as the date attribute.
Default is |
... |
Arbitrary arguments to use with |
The file name can be one with a valid ISO 8601 date (yyyy-mm-dd) already in it, or it can be a file name with the date elided.
For example, if there is a file you'd like to read on your disk called "iris-2021-05-08.csv", you can call this function with either "iris.csv" or "iris-2021-05-08.csv" as the file name.
When you call this function with a file name without an ISO 8601 date (e.g. "iris.csv.gz"), the file name extension ".csv.gz" is removed and the function looks for a file name beginning with "iris", a date, and the file extension. The file extension is considered to be anything after the first period in the base name. For example, if the file name given is "./my.data/iris.csv.gz", the extension is ".csv.gz". This means no period can be present in the base file name (after any directories) with the exception of the file extension.
If you call this function with "iris.csv" and there is no file name
with an ISO 8601 date appended to that file name on your disk, and
allow.fallback.date
is TRUE
, then the lb.date
attribute is set to the current date.
A data.table
with an attribute called lb.date
set
## Not run:
# there's a file called "iris-2021-05-08.csv" on disk
dat <- fread_plus_date("iris.csv")
attribute(dat)$lb.date
# [1] "2021-05-08
# can also read the full file name
dat <- fread_plus_date("iris-2021-05-08.csv")
attribute(dat)$lb.date
# [1] "2021-05-08
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.