When using a species list with duration and growth habit variables that aren'tDuration and GrowthHabitSub, the resulting output still has the variables Duration and GrowthHabitSub and they, rather than the specified variables, contain the species information for the generic species. Since the user is specifying the variables that those data belong in, it shouldn't be terrible to put the information into the specified/requested variables as a final step in the function.
# Where do we expect values for duration or growth habit but have NAs?
missing_duration_indices <- is.na(generic_species[[species_duration]])
missing_growth_habit_indices <- is.na(generic_species[[species_growth_habit_code]])
# If there are any species missing that information, write in values from
# the hardcoded lookup table variables because we know what they are.
# Any species that aren't generic but don't have growth habit or duration info
# will just get the NA from the hardcoded column.
if (any(missing_duration_indices)) {
generic_species[[species_growth_habit_code]][missing_duration_indices] <- as.character(generic_species[["Duration"]][missing_duration_indices])
}
if (any(missing_growth_habit_indices) {
generic_species[[species_duration]][missing_growth_habit_indices] <- as.character(generic_species[["GrowthHabitSub"]][missing_growth_habit_indices])
}
When using a species list with duration and growth habit variables that aren't
Duration
andGrowthHabitSub
, the resulting output still has the variablesDuration
andGrowthHabitSub
and they, rather than the specified variables, contain the species information for the generic species. Since the user is specifying the variables that those data belong in, it shouldn't be terrible to put the information into the specified/requested variables as a final step in the function.