This function helps to extract dates from a vector of files.
extractDate(files, pos1, pos2, asDate = FALSE, format = "%Y%j")
A character
vector of filenames from which to extract
dates. Alternatively, a Raster*
with date information in its layer
names
.
Start and end of date string in files
as
integer
. If missing, positions are tried to be retrieved from a
look-up table provided that 'files' comply with the MODIS standard naming
convention.
logical
. If TRUE
, the result is converted to a
Date
object.
character
, date format. Used only if asDate = TRUE
.
Defaults to MODIS date style (i.e., "%Y%j"
for year and julian day).
See strptime
for modifications.
A list
with the following entries: 'inputLayerDates', 'pos1', 'pos2',
'asDate' and, optionally, 'format'. If asDate = FALSE
,
'inputLayerDates' are represented as character
, else as Date
.
# NOT RUN {
# example on HDF files
files <- c("MOD13Q1.A2010209.h18v03.005.2010239071130.hdf",
"MOD13Q1.A2010225.h18v03.005.2010254043849.hdf")
extractDate(files)
extractDate(files, asDate = TRUE)
# on any other file
files <- c("Myfile_20010101.XXX", "Myfile_20010115.XXX", "Myfile_20010204.XXX")
extractDate(files, pos1 = 8, pos2 = 15)
extractDate(files, pos1 = 8, pos2 = 15, asDate = TRUE, format = "%Y%m%d")
# }
Run the code above in your browser using DataLab