Takes a data.table
, a file name, and writes it with
data.table::fwrite
.
fwrite_plus_date(
DT,
fname,
from.attribute = TRUE,
allow.fallback.date = TRUE,
...
)
a data.table
to write to disk
The file name to write the data.table
to. The
date will be appended between the file name and its
file extension
A logical indicating whether the date should
be taken from the lb.date
attribute of
the data.table
, or whether it should be
today's date. Default (TRUE
) takes it
from the lb.date
attribute.
A logical indicating, if there is no
lb.date
attribute in the supplied
data.table
, whether it is permissible
to use today's date, instead.
Default is TRUE
.
Arbitrary arguments to pass to fwrite
The supplied file name will be modified to include an ISO 8601 date
(yyyy-mm-dd) between the file name and the file extension. Under the
default settings, the date used will be from the lb.date
attribute of the supplied data.table
. If there is no lb.date
attribute, the current date will be used, instead.
For example, if there is a data.table
with an lb.date
attribute of "2021-05-08", and you supply this function with the file
name "iris.csv", the file name actually written to disk will be
"iris-2021-05-08.csv". Under the default settings, if there is no
lb.date
attribute, but today's date is "2038-01-19", the file
name written to disk will be "iris-2038-01-19.csv".
The ISO 8601 date is sandwiched between the file name 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 (FALSE) {
set_lb_date(iris, "2021-05-08")
fwrite_plus_date(iris, "iris.csv.gz")
# "iris-2021-05-08.csv.gz" is now written to disk
}
Run the code above in your browser using DataLab