resolve_cultures {srppp} | R Documentation |
Resolve culture specifications to their lowest hierarchical level
Description
Resolves culture levels in a dataset to their lowest hierarchical level (leaf
nodes) using a parent-child relationship dataset derived from a culture tree
using the German culture names. Only German culture names are supported. If
no match is found, the function assigns NA
to the leaf_culture_de
column.
If correct_culture_names
is set to TRUE
, the function corrects variations
in the naming of aggregated culture groups with "allg.".
Usage
resolve_cultures(
dataset,
srppp,
culture_column = "culture_de",
application_area_column = "application_area_de",
correct_culture_names = TRUE,
resolve_culture_allg = TRUE
)
Arguments
dataset |
A data frame or tibble containing the data to be processed. It should include a column that represents the culture information to be resolved. |
srppp |
An srppp_dm object. From this object the relations from each culture to the leaf cultures (lowest level in the hierarchical tree) are used, which are stored as attribute 'culture_leaf_df' of the culture tree, which is itself stored as an attribute of the object. |
culture_column |
(Optional) A character string specifying the column in
the dataset that contains the culture information to be resolved. Defaults
to |
application_area_column |
(Optional). A character string specifing the name of the column in dataset containing application area information. Default is "application_area_de". |
correct_culture_names |
If this argument is set to |
resolve_culture_allg |
If this argument is set to |
Details
The resolve_cultures
function processes the input dataset as
follows
Leaf Node Resolution: The cultures in the specified column of the dataset are resolved to their
lowest hierarchical level (leaf nodes) based on the culture_leaf_df
mapping.
The result is an expanded dataset that includes an additional column
(leaf_culture_de
) containing the resolved cultures at their lowest level.
Value
A data frame or tibble with the same structure as the input
dataset
, but with an additional column "leaf_culture_de"
that contains
the resolved leaf culture levels. For cultures, that are not defined
in the register, the leaf culture is set to NA
.
Examples
library(srppp)
sr <- try(srppp_dm())
if (inherits(sr, "try-error")) {
sr <- system.file("testdata/Daten_Pflanzenschutzmittelverzeichnis_2024-12-16.zip",
package = "srppp") |>
srppp_xml_get_from_path(from = "2024-12-16") |>
srppp_dm()
}
example_dataset_1 <- data.frame(
substance_de = c("Spirotetramat", "Spirotetramat", "Spirotetramat", "Spirotetramat"),
pNbr = c(7839, 7839, 7839, 7839),
use_nr = c(5, 7, 18, 22),
application_area_de = c("Obstbau", "Obstbau", "Obstbau", "Obstbau"),
culture_de = c("Birne", "Kirsche", "Steinobst", "Kernobst"),
pest_de = c("Birnblattsauger", "Kirschenfliege", "Blattläuse (Röhrenläuse)", "Spinnmilben"))
# Same as above, but with culture name "Kirschen" instead of "Kirsche"
example_dataset_2 <- data.frame(
substance_de = c("Spirotetramat", "Spirotetramat", "Spirotetramat", "Spirotetramat"),
pNbr = c(7839, 7839, 7839, 7839),
use_nr = c(5, 7, 18, 22),
application_area_de = c("Obstbau", "Obstbau", "Obstbau", "Obstbau"),
culture_de = c("Birne", "Kirschen", "Steinobst", "Kernobst"),
pest_de = c("Birnblattsauger", "Kirschenfliege", "Blattläuse (Röhrenläuse)", "Spinnmilben"))
resolve_cultures(example_dataset_1, sr)
# Here we get NA for the leaf culture of "Kirschen"
resolve_cultures(example_dataset_2, sr)
# Example showing how cereals "Getreide" are resolved
example_dataset_3 <- data.frame(
substance_de = c("Pirimicarb"),
pNbr = c(2210),
use_nr = c(3),
application_area_de = c("Feldbau"),
culture_de = c("Getreide"),
pest_de = c("Blattläuse (Röhrenläuse)") )
resolve_cultures(example_dataset_3, sr)
# Example resolving ornamental plants ("Zierpflanzen")
example_dataset_4 <- data.frame(substance_de = c("Metaldehyd"),
pNbr = 6142, use_nr = 1, application_area_de = c("Zierpflanzen"),
culture_de = c("Zierpflanzen allg."), pest_de = c("Ackerschnecken/Deroceras Arten") )
resolve_cultures(example_dataset_4, sr)
# Illustrate the resolution of the culture "allg."
example_dataset_5 <- data.frame(
substance_de = c("Kupfer (als Oxychlorid)","Metaldehyd","Metaldehyd","Schwefel"),
pNbr = c(585,1090,1090,38),
use_nr = c(12,4,4,1),
application_area_de = c("Weinbau","Obstbau","Obstbau","Beerenbau"),
culture_de = c("allg.","allg.","allg.","Brombeere"),
pest_de = c("Graufäule (Botrytis cinerea)","Wegschnecken/Arion Arten",
"Wegschnecken/Arion Arten","Gallmilben"))
resolve_cultures(example_dataset_5, sr, resolve_culture_allg = FALSE)
resolve_cultures(example_dataset_5, sr)
# Illustrate the resolution of "Obstbau allg.", which does not have children in
# the XML files, but which should have children, because Obstbau allg. is
# not a leaf culture.
example_dataset_6 <- data.frame(
substance_de = c("Schwefel"),
pNbr = c(3561),
use_nr = c(4),
application_area_de = c("Obstbau"),
culture_de = c("Obstbau allg."),
pest_de = c("Wühl- oder Schermaus") )
resolve_cultures(example_dataset_6, sr,
correct_culture_names = FALSE)
resolve_cultures(example_dataset_6, sr,
correct_culture_names = TRUE)