export_cdt: Export daily or dekadal data in the format for CDT

View source: R/export_cdt.R

export_cdtR Documentation

Export daily or dekadal data in the format for CDT

Description

export_cdt rearranges a data frame using prepare_cdt to a format suitable for use in CDT. The data frame is then written to a file or connection.

Usage

export_cdt(
  data,
  station,
  element,
  latitude,
  longitude,
  altitude,
  type = c("dekad", "daily"),
  date_time = NULL,
  year = NULL,
  month = NULL,
  dekad = NULL,
  metadata = NULL,
  file_path = paste0("CDT-", element, ".csv"),
  ...
)

Arguments

data

data.frame data.frame of daily or dekadal climatic data in tidy format i.e. one row per time point (per station) and one column per element.

station

character(1) Name of the station identifying column in data.

element

character(1) Name of the element column in data.

latitude

character(1) Name of the latitude column in metadata.

longitude

character(1) Name of the longitude column in metadata.

altitude

character(1) Name of the altitude column in metadata.

type

character(1) Character indicating the type of data, either "dekad" or "daily".

date_time

character(1) Name of the date column in data. Required if type = "daily". If type = "dekad" this is only needed if year, month, and dekad are not specified.

year

character(1) Name of the year column in data. Only needed if type = "dekad". If NULL it will be created using lubridate::year(data[[date_time]]).

month

character(1) Name of the month column in data. Only needed if type = "dekad". If NULL it will be created using lubridate::month(data[[date_time]]).

dekad

character(1) Name of the dekad column in data. Only needed if type = "dekad". If NULL it will be created using dekad function.

metadata

data.frame data.frame of station metadata. Use this is the station details are in a separate data.frame with one row per station. If specified, latitude, longitude and altitude are assumed to be in metadata and station must be in both data and metadata to facilitate joining.

file_path

character(1) A character specifying the file path and file name to export.

...

Other parameters passed to write.csv().

Value

Invisibly returns the file path of the saved data.

Examples

# To write daily_niger data to CDT format
# NOT RUN:
#           date_time = "date", latitude = "lat", longitude = "long", altitude = "alt",
#           metadata = stations_niger)

IDEMSInternational/cdms.products documentation built on July 7, 2023, 10:13 a.m.