format_sort_term {openFDA} | R Documentation |
Format character vectors into sort
terms for openFDA API queries
Description
This function acts as a helper for constructing a sort term in the openFDA API.
Usage
format_sort_term(sort)
Arguments
sort |
A single-length character vector of length 1. If unnamed, it will be assumed that you have already formatted your search string to work with the API. If named, the vector will be collapsed to include your field and sorting choice. |
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")
# Provide a named vector and the function will format it for you
format_sort_term(c("openfda.generic_name" = "asc"))
# Errors will be thrown if you supply a bad input
try(format_sort_term("receivedate:no_order"))
try(format_sort_term(c("receivedate" = "ascending")))