ropensci / webchem

Chemical Information from the Web
https://docs.ropensci.org/webchem
Other
160 stars 40 forks source link

is.na > 1 error #406

Closed bmgarcia closed 1 year ago

bmgarcia commented 1 year ago

Hello,

I am trying to use cir_query on a list of compound "common names" to convert these to "smiles". When I run this (and most of the other webchem functions) on this list I get the following error:

cir_query(mets,"smiles","all")

Error in if (is.na(identifier)) { : the condition has length > 1

Can you provide some guidance on why I am getting this error and how to resolve it?

Thank you, Brianna Garcia

Aariq commented 1 year ago

Thanks for reporting this issue. Can you provide a reproducible example? (e.g., I'm not sure what mets is in this example)

bmgarcia commented 1 year ago

Aariq,

Hello - apologies for not attaching the example. It looks like I've resolved the issue - the initial upload of the compound name list was in the form of a tibble rather than a character vector, after changing the format the code seems to run as expected.

Aariq commented 1 year ago

Ah ok, thanks! We might want to add some checks that inputs are of the expected type.

stitam commented 1 year ago

Thanks @bmgarcia for raising this issue! @Aariq I know we use match.arg() for some argument types but that wouldn't work for queries. Wondering if something like stopifnot(is.character(query)) could solve this? What do you think?

Aariq commented 1 year ago

Yup, stopifnot(is.character(query)) would be sufficient. Another option is the assertthat package which produces friendlier error messages by default. It has zero dependencies so it would only introduce itself as a dependency if we wanted to use it. Might open a separate issue for it so we can keep track of which functions have this and which still need it. Not a huge priority I think, but probably good to do eventually.