Skip to contents

Harmonize planting info Reshapes the planting info table based on specifications set by the user. To aid in merging with yield data.

Usage

harmonize_planting_info(
  planting_info = NULL,
  replant_dates = c("latest", "rows", "columns")[1],
  include_component_crops = TRUE
)

Arguments

planting_info

A data frame of the planting_info table from the DRIVES database. If NULL, this will be downloaded from the Directus database.

replant_dates

Indicates how multiple planting dates should be organized in the output. There are three options: latest, rows, and columns.

"latest" means that the output dataframe will exclude earlier dates from replanted plots, assuming that these were unsuccessful.

"rows" means that the output dataframe will include organize multiple planting dates into separate rows.

"columns" means that the output dataframe will organize multiple planting dates into separate columns.

include_component_crops

TRUE or FALSE indicating whether the output should include information about components of crop mixtures (component_crop_id). If TRUE, the output dataframe will include component crop information in separate columns.

Value

A dataframe of planting information arranged as either: 1) one row per unit_id/harvest_year/actual_crop_id (if replant_dates is "latest" or "columns") 2) one row per unit_id/harvest_year/actual_crop_id/planting_date (if replant_dates is "rows")

If include_component_crops is TRUE, output columns will include suffixes "_1", "_2", etc. for multiple components, based on the component_crop_index column. If replant_dates is also set to "columns", output columns will include suffixes "_d1_c1","d1_c2","_d2_c1","_d2_c2, etc. for multiple components within each date.

If include_component_crops is FALSE, the output will include an additional integer column, num_component_crops indicating the number of component crops planted on that date. This does not consider component crops planted on earlier planting dates. Also, the output keeps variety_id and planting_rate information for dates with only one component.

If replant_dates is set to "latest", the output will include an added logical column, replantedTF indicating whether a plot was replanted. The value of date_index indicates how many times the plot was replanted.

Examples

# latestWithComponents <- harmonize_plantinfo(replant_dates = "latest", include_component_crops = TRUE)
# latestWithoutComponents <- harmonize_plantinfo(replant_dates = "latest", include_component_crops = FALSE)
# rowsWithComponents <- harmonize_plantinfo(replant_dates = "rows", include_component_crops = TRUE)
# rowsWithoutComponents <- harmonize_plantinfo(replant_dates = "rows", include_component_crops = FALSE)
# columnsWithComponents <- harmonize_plantinfo(replant_dates = "columns", include_component_crops = TRUE) 
# columnsWithoutComponents <- harmonize_plantinfo(replant_dates = "columns", include_component_crops = FALSE