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
Alternatives for handling NA inputs #225
Conversation
Codecov Report
@@ Coverage Diff @@
## master #225 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 19 19
Lines 1587 1675 +88
======================================
- Misses 1587 1675 +88
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by match == "na"
. Maybe you could clarify what that "does" or see if my suggestions allow you to get rid of that code entirely.
This PR is meant to contribute to the discussion on issue #224.
The interesing part is in
chebi.R
. The issue is that if the input is invalid, e.g."balloon"
(unknown chemical) orNA
, the structure of the output will be different, which makes vectorisation difficult. As a reprex,chebi_comp_entity(c("CHEBI:89301","CHEBI:89302","balloon",NA))
will return a nicely formatted list for the first two entries and something else for the last two. This makessapply(test, function(x) x[["properties"]]$inchikey)
return NULL-s, and unable to coerse the output into a character vector.My approach for handling invalid inputs is to return an empty object with the same structure but all
NA
-s. I tried two alternatives: inget_chebiid()
I defined the structure twice within the function. Inchebi_comp_entity()
this would have been distrubingly complex, so I created a separate, non exported function, which generates an object with the correct structure, but allNA
-s inside, and called this function in lines 226 and 251. Forcing to return an empty object for invalid inputs allowedsapply()
to extract inchikeys and coerce the output to a character vector.I think the second approach is more elegant and less error prone. What do you think about the these empty objects? Can you suggest other solutions?
PR task list:
devtools::document()