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

Make dedicated error checking funtions #100

Open
Neves-P opened this issue Mar 18, 2020 · 0 comments
Open

Make dedicated error checking funtions #100

Neves-P opened this issue Mar 18, 2020 · 0 comments

Comments

@Neves-P
Copy link
Collaborator

Neves-P commented Mar 18, 2020

Quoting @richelbilderbeek #90:

) {
  testit::assert(
    "length(pars) is not five and/or shift_times is not null, set
    five parameters with no shift_times or ten parameters with
    non-null shift_times",
    length(pars) == 5 || (length(pars) == 10 && !is.na(prop_type2_pool))
  )
  testit::assert(
    "2 type islands cannot have species on the island initially",
    is.na(prop_type2_pool) || !is.na(prop_type2_pool) && nonoceanic_pars[1] == 0
  )
  testit::assert(
    "prop_type2_pool should either be NA for no type 2 species or value between
    0 and 1",
    is.na(prop_type2_pool) || (prop_type2_pool >= 0 && prop_type2_pool <= 1)
  )

I enjoy this error checking!

But first, this error checking is already quite complex. Use a function
for each check instead: this will be easier to debug, easier to read,
easier to write.

Second, it is getting clear that the function
is actually doing two things: check for 5 or 10 parameters. I suggest that
this function quickly redirects to functions specialized on 5 or 10 parameters.
Of course, there should be little code duplication, so things done for both
5 and 10 parameters should be put into little functions as well.

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