Landscape-Data-Commons / terradactyl

Tools for using terrestrial core methods data
Other
3 stars 4 forks source link

generic_growth_habits() sometimes adds extra duration and growth habit columns #119

Closed nstauffer closed 1 year ago

nstauffer commented 1 year ago

When using a species list with duration and growth habit variables that aren't Duration 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])
}
nstauffer commented 1 year ago

See #120 for files and code that can be used to reproduce this.