webchem icon indicating copy to clipboard operation
webchem copied to clipboard

improve bcpc_query()

Open andschar opened this issue 5 years ago • 1 comments

aw_query() currently returns a list of lists of vectors, when it finds a match and a vector NA of length 1, if it doesn't. In my opinion this is quite cumbersome to wrangle with in R. Example:

todo = c("630-20-6", "1070-78-6", "1071-83-6", "79-34-5")
aw = webchem::aw_query(todo, from = 'cas')

The first two entries are NA vectors with length 1, the second two entries are lists of vectors. In my opinion it would be better to return a tibble if something is found, because one can use data.table::rbindlist() or dplyr::bind_rows() then. E.g.: data.table::rbindlist(aw[ !is.na(aw) ]). Though, we could also think about returning tibble::tibble(query = '630-20-6') in the case of no match instead of NA, meaning one wouldn't have to exclude NA explicitly when binding. AW returns tabular-freinldy data, so I think it's quite easy to implement the tibbles.

This also belongs to #218.

Also, aw_query() results have the class attribute aw_query assigned. Designed by @EDiLD to work with the S3-OO system. Should we continue using this? Lately, we haven't made use of any OO-functions. I think we haven't really agreed on that up to now. Also to discuss further in #228.

andschar avatar Sep 29 '20 12:09 andschar

Just wanted to note that this still applies to bcpc_query()

Aariq avatar Jan 05 '22 18:01 Aariq