RHoMIS / rhomis-R-package

An R package for essential processing of data collected with RHoMIS
GNU General Public License v3.0
4 stars 4 forks source link

Shorten unit conversions and clean up hardcoded gender categories #22

Closed ekuw closed 2 years ago

ekuw commented 2 years ago

Trying to move away from multiple if statements in favour of looping over variables. In some cases the naming scheme of variables makes these functions more complicated than they could be, and for now I've put some dictionaries in the pkg.env so that variable names can be mapped in some of the functions in the UnitsAndConversions module.

For example: `assign("local_units_file_tibble_list",

list("country"          = "country",
     "crop_name"        = "crop_name",
     "livestock_name"   = "livestock_name",
     "crop_yield_units" = "crop_yield_units",
     "crop_sold_price_quantityunits" = "crop_price_units",
     "unitland"         = "land_area_units",
     "milk_units"       = "milk_amount_units",
     "milk_sold_price_timeunits" = "milk_price_time_units",
     "bees_honey_production_units" = "honey_amount_units",
     "eggs_units" = "eggs_amount_units",
     "eggs_sold_price_timeunits" = "eggs_price_time_units",
     "fertiliser_units" = "fertiliser_units"),`

here on the left we have the string that precedes ".csv" in the unit conversion file names, and on the right is the name of the variable assigned to the .GlobalEnv in UnitsAndConversions.R... if only these names were consistent and this dictionary was rendered unnecessary. To be discussed!

As discussed, I also moved the gender categories into a pkg.env variable. We can decide how to handle internal data later, for now it is probably more important that we migrate repeated hard-coded values from the code. We should think about which functions users are likely to call and which functions will really only be called via other functions.