mikejohnson51 / hydrofab

Hydrofabric Fabricator
Creative Commons Zero v1.0 Universal
9 stars 4 forks source link

Error check on clean_geometries() keep value #23

Open anguswg-ucsb opened 1 year ago

anguswg-ucsb commented 1 year ago

I am proposing to add a check on the keep argument in hydrofab::clean_geometries() to make sure that keep is > 0 and <= 1.

This is a requirement for the rmapshaper::ms_simplifyfunction that runs at the end of clean_geometries, and an error will be thrown if keep does not meet the condition 0 < keep <= 1

Currently hydrofab::clean_geometries() has to run through all of its logic before this error gets raised, so I am suggesting we add the keep check at the start of the function so if a user provides an invalid keep value, clean_geometries() will stop immediately and raise an error, instead of spending time processing geometries that will result in an error down the line.

Suggested code change to clean_geometries():

clean_geometry <- function(catchments,
                           ID = "ID",
                           keep = NULL,
                           crs = 5070,
                           grid = .0009,
                           sys = NULL
                           ) {

  # Check to make sure keep is valid 
  if (keep < 0 || keep > 1) {

    stop("Invalid value for 'keep'. 'keep' must be > 0 and <= 1")

  } 

  # function continues as is
  # ...