Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error check on clean_geometries() keep value #23

Open
anguswg-ucsb opened this issue May 31, 2023 · 0 comments
Open

Error check on clean_geometries() keep value #23

anguswg-ucsb opened this issue May 31, 2023 · 0 comments

Comments

@anguswg-ucsb
Copy link

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_simplify function 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
  # ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant