View source: R/format_search_term.R
format_search_term | R Documentation |
search
terms for openFDA API queriesThis function is a helper for constructing search queries. Whilst it handles some of the available formatting for openFDA APIs, it does not recapture all of the search term syntax available to you. To get a full appreciation of the openFDA search syntax, see https://open.fda.gov/apis/advanced-syntax/.
format_search_term(search, exact = TRUE, mode = "or")
search |
A character vector of length 1 or more. If scalar and 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
various search terms, separated by AND or OR terms based on the value of
|
exact |
A single-length logical vector. When This parameter only applies if |
mode |
A single-length character vector, which defines how searches in
multiple fields should be combined. By default ( This parameter only applies if |
A character vector of the S3 class <AsIS>
, with a formatted search
term which can be supplied to openFDA()
.
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.
format_sort_term()
performs similar formatting for the sort
component
of an openFDA query.
I()
generates vectors with the <AsIs>
S3 class.
httr2::req_url()
documents why I()
is applied to the output of this
function.
# Provide a formatted search string and the function will do no formatting
format_search_term("openfda.generic_name:verapamil")
# Provide a named vector and the function will format it for you
format_search_term(c("openfda.generic_name" = "verapamil"))
# If providing multiple elements in your search term, use `exact = FALSE`
# to prevent the function from surrounding the term with double quotes.
format_search_term(c("openfda.generic_name" = "verapamil+amlodipine"),
exact = FALSE)
# Provide a longer named vector and function will merge these with an OR
# operator
format_search_term(c("openfda.generic_name" = "verapamil",
"openfda.manufacturer_name" = "glaxo*"))
# Or you can set the `mode` argument to merge your search terms with an AND
# operator
format_search_term(c("openfda.generic_name" = "verapamil",
"openfda.manufacturer_name" = "glaxo*"),
mode = "and")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.