extractDate.Rd 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/extractDate.R
  3. \name{extractDate}
  4. \alias{extractDate}
  5. \title{Extract Dates from (MODIS) Files}
  6. \usage{
  7. extractDate(files, pos1, pos2, asDate = FALSE, format = "\%Y\%j")
  8. }
  9. \arguments{
  10. \item{files}{A \code{character} vector of filenames from which to extract
  11. dates. Alternatively, a \code{Raster*} with date information in its layer
  12. \code{\link[raster]{names}}.}
  13. \item{pos1, pos2}{Start and end of date string in \code{files} as
  14. \code{integer}. If missing, positions are tried to be retrieved from a
  15. look-up table provided that 'files' comply with the MODIS standard naming
  16. convention.}
  17. \item{asDate}{\code{logical}. If \code{TRUE}, the result is converted to a
  18. \code{Date} object.}
  19. \item{format}{\code{character}, date format. Used only if \code{asDate = TRUE}.
  20. Defaults to MODIS date style (i.e., \code{"\%Y\%j"} for year and julian day).
  21. See \code{\link{strptime}} for modifications.}
  22. }
  23. \value{
  24. A \code{list} with the following entries: 'inputLayerDates', 'pos1', 'pos2',
  25. 'asDate' and, optionally, 'format'. If \code{asDate = FALSE},
  26. 'inputLayerDates' are represented as \code{character}, else as \code{Date}.
  27. }
  28. \description{
  29. This function helps to extract dates from a vector of files.
  30. }
  31. \examples{
  32. # example on HDF files
  33. files <- c("MOD13Q1.A2010209.h18v03.005.2010239071130.hdf",
  34. "MOD13Q1.A2010225.h18v03.005.2010254043849.hdf")
  35. extractDate(files)
  36. extractDate(files, asDate = TRUE)
  37. # on any other file
  38. files <- c("Myfile_20010101.XXX", "Myfile_20010115.XXX", "Myfile_20010204.XXX")
  39. extractDate(files, pos1 = 8, pos2 = 15)
  40. extractDate(files, pos1 = 8, pos2 = 15, asDate = TRUE, format = "\%Y\%m\%d")
  41. }
  42. \author{
  43. Matteo Mattiuzzi
  44. }