stevecondylios / dictionaRy

An R interface to the English Dictionary
Other
6 stars 0 forks source link

Consider whether NA or error is best when word definition is unavailable #3

Closed stevecondylios closed 2 years ago

stevecondylios commented 2 years ago

Consider whether define() should return NA or error when a word is unavailable. Current behaviour is for it to error, which may somewhat complicate use with multiple terms.

AlunHewinson commented 2 years ago

Strong agree on the NA. If we want to pass a vector of words through define(), the error stops it in its tracks. This forces the user to write a loop that handles errors.

stevecondylios commented 2 years ago

Thanks again for your feedback @AlunHewinson

As at a652f41b63873439e6ba95132b8f0a48bfcac6de, define() now returns a 0 row tibble when a word is not found, such that any mapping functions which rbind the results will function seamlessly when iterating over a vector of word inputs and one or more are not found.

For example this

words <- c("paint", "sldkfjlsdjkf")
purrr::map_df(words, ~ define(.x))

will now succeed despite "sldkfjlsdjkf" not being an English word.