Skip to contents

Performs initial data processing steps for crop yield data. These include: - Filling in missing actual_crop_id with expected_crop_id. - Calculating dry yield from yield and yield_percent_moisture (for crops with yields reported at standardized moisture). - Adding a TRUE FALSE column for cover crops. - Optionally, the function can reshape the data into a wide format, with multiple crop fractions (e.g., grain and straw) in separate columns instead of separate rows, as they are organized in the database. This option may be convenient for harvest index calculations and such.

Usage

harmonize_yields(
  crop_yields = NULL,
  crop_fractions_as_columns = FALSE,
  primary_crop_fractions = getOption("drivesR.primary_crop_fractions")
)

Arguments

crop_yields

A data frame of the crop_yields table from the DRIVES database. If left as NULL, this table will be downloaded via the Directus API.

crop_fractions_as_columns

If TRUE, multiple fractions from the same crop are organized in separate columns. If FALSE, multiple fractions from the same crop are organized in separate rows, as in the database table.

primary_crop_fractions

A vector of crop fractions to select as the primary fraction, when there is more than one. So far, this only pertains to grain and tomato fruit. The default is set with the option drivesR.primary_crop_fractions.

Value

A data frame of lightly processed crop yield data. Information stored in the table is used to generate new columns, including dry yield (in kg/ha) and a TRUE/FALSE column for cover crops.

If crop_fractions_as_columns is set to TRUE, data describing fractions from the same crop will be described in separate columns, with suffix _1 for the primary fraction and _2, _3, etc. for other fractions.

Examples

# not run: longyield <- harmonize_yields(crop_fractions_as_columns = FALSE)
# not run: wideyield <- harmonize_yields(crop_fractions_as_columns = TRUE)