Skip to content

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

@valentinitnelav

Description

@valentinitnelav

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.

Metadata

Metadata

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions