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

Replace all try() with tryCatch() when bootstrapping #32

Open
valentinitnelav opened this issue Nov 5, 2020 · 0 comments
Open

Replace all try() with tryCatch() when bootstrapping #32

valentinitnelav opened this issue Nov 5, 2020 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@valentinitnelav
Copy link
Owner

valentinitnelav commented Nov 5, 2020

Would it be better to replace all the try statements with tryCatch, because we can assign return values like NA in case of error?

So, for example in boot_networklevel_once(), instead of having this:

  for (i in 1:length(ids_lst)){
    metric_lst[[i]] <- try({
      web <- data[ids_lst[[i]], table(get(col_lower), get(col_higher))]
      set.seed(42)
      bipartite::networklevel(web = web, index = index, level = level, ...)
    })
  }

we could better have this:

  for (i in 1:length(ids_lst)){
    metric_lst[[i]] <- tryCatch({
      web <- data[ids_lst[[i]], table(get(col_lower), get(col_higher))]
      set.seed(42)
      bipartite::networklevel(web = web, index = index, level = level, ...)
    },
    error = function(e) NA)
  }

This will return NA-s in case of errors, though it might be dangerous because try can be still informative because it can return the error message ...
Though tryCatch can also be 'instructed' to pass the error message, but is just getting more verbose than try in that case.

@valentinitnelav valentinitnelav added the question Further information is requested label Nov 5, 2020
@valentinitnelav valentinitnelav self-assigned this Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant