export_cdt_dekad: Export dekad data in CDT format

View source: R/export_cdt_dekad.R

export_cdt_dekadR Documentation

Export dekad data in CDT format

Description

export_cdt_dekad takes a data frame that has elements summarised by dekad. This data frame is then rearranged using prepare_cdt_dekad to a format suitable for use in CDT, and then written to a file or connection.

Usage

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

Arguments

data

data.frame data.frame of dekadal climatic data in tidy format i.e. one row per dekad (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.

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.

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.

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
# first put daily_niger data into a dekad format
data(daily_niger)
summary_data <- daily_niger %>%
                   dplyr::mutate(dekad_date = dekad(daily_niger$date)) %>%
                   dplyr::group_by(station_name, year, dekad_date) %>%
                   dplyr::summarise(date = dplyr::first(date), sum = sum(tmax))
# NOT RUN:
#export_cdt_dekad(data = daily_niger, station = "station_name", element = "rain",
#           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.