Format character vectors into sort
terms for openFDA API queries
Source: R/format_sort_term.R
format_sort_term.Rd
This function acts as a helper for constructing a sort term in the openFDA API.
Value
A character vector of the S3 class <AsIS>
, with a formatted search
term which can be supplied to openFDA()
.
Note
This function does not check that you're providing accurate field names or search terms. It is up to you to make sure you've provided correctly spelt fields and search terms.
See also
format_search_term()
performs similar formatting for thesearch
component of an openFDA query.I()
generates vectors with the<AsIs>
S3 class.httr2::req_url()
documents whyI()
is applied to the output of this function.
Examples
# Provide a formatted search string and the function will do no formatting
format_sort_term("openfda.generic_name:asc")
#> [1] "openfda.generic_name:asc"
# Provide a named vector and the function will format it for you
format_sort_term(c("openfda.generic_name" = "asc"))
#> [1] "openfda.generic_name:asc"
# Errors will be thrown if you supply a bad input
try(format_sort_term("receivedate:no_order"))
#> Error in format_sort_term("receivedate:no_order") :
#> `sort` must end with either "asc" or "desc".
#> ! `sort` was "receivedate:no_order".
try(format_sort_term(c("receivedate" = "ascending")))
#> Error in format_sort_term(c(receivedate = "ascending")) :
#> `sort` must be either "asc" or "desc".
#> ! `sort` was "ascending".