generate_filenames: Generate filenames from a template and arguments

View source: R/generate_filenames.R

generate_filenamesR Documentation

Generate filenames from a template and arguments

Description

This is a more flexible replacement for the get_filenames function. The main difference is that it allows you to pass any argument that might exist to be substituted in the file name. These arguments are passed through ...

Usage

generate_filenames(
  file_path = getwd(),
  file_date = Sys.Date(),
  start_date = NULL,
  end_date = NULL,
  by = "6h",
  lags = "0s",
  file_template = "fctable",
  filenames_only = TRUE,
  ...
)

Arguments

file_path

The parent path to all file names. All file names are generated to be under the file_path directory. The default is the current working directory.

file_date

Forecast date for file names. Can be in YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss format. Can be numeric or charcter. If not passed the system time in YYYYMMDD format is used.

start_date

Date of the first forecast for file names. Can be in YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss format. Can be numeric or charcter. If NULL, file_date must be specified. If not NULL, end_date must also be specified.

end_date

Date of the last forecast for file names. Can be in YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss format. Can be numeric or charcter. Used in conjunction with start_date and by.

by

The time between new forecasts. If numeric, it is assumed to be in hours, but the time units may be given by a letter after the number where d = days, h = hours, m = minutes and s = seconds. A sequence of forecasts dates is generated from start_date to end_date every by.

lags

A named list of members of an ensemble forecast model that are lagged and the amount by which they are lagged. The list names are the names of those forecast models, as given in fcst_model that have lagged members, and the lags are given as vectors that are the same length as the members vector. If the lags are numeric, it is assumed that they are in hours, but the units may be specified with a letter after each value where d = days, h = hours, m = minutes and s = seconds. lags is primarily used to generate the correct file names for lagged members - for example a lag of 1 hour will generate a file name with a date-time 1 hour earlier than the date-time in the sequence (start_data, end_date, by = by) and a lead time 1 hour longer.

file_template

A template for the file names. For available built in templates see show_file_templates. If anything else is passed, it is returned unmodified, or with substitutions made for dynamic values. Available substitutions are YYYY for year, {MM} for 2 digit month with leading zero, {M} for month with no leading zero, and similarly {DD} or {D} for day, {HH} or {H} for hour, {mm} or {m} for minute. Also {LDTx} for lead time and {MBRx} where x is the length of the string including leading zeros. Note that the full path to the file will always be file_path/template.

filenames_only

Logical. If TRUE (the default), a vector of file names will be returned, otherwise if FALSE a data frame will be returned with the metadata that was used to generated the file names included.

...

Other arguments for substitutions in file_template. Note that for ensemble members, members may be used for the {MBRx} substitution.

Value

A character vector or a data frame.

Examples

generate_filenames(fcst_model = "my_model", parameter = "T2m")
generate_filenames(
  fcst_model     = "my_model",
  lead_time      = seq(0, 12),
  file_template  = "vfld",
  filenames_only = FALSE
)
generate_filenames(
  sub_model      = "my_model",
  lead_time      = seq(0, 12),
  file_template  = "vfld_eps",
  members        = seq(0, 5)
)
generate_filenames(
  start_date     = 2020010100,
  end_date       = 2020013100,
  by             = "1d",
  fcst_model     = "my_model",
  lead_time      = seq(0, 3),
  file_path      = "/path/to/my/data",
  file_template  = "{fcst_model}_v{version}_{YYYY}{MM}{DD}{HH}{mm}{ss}_mbr{MBR5}+{LDT3}",
  members        = seq(0, 1),
  version        = c(2, 3, 5)
)

andrew-MET/harpIO documentation built on March 7, 2024, 7:48 p.m.