This specialized template handles the nested payload structure common to the
EPA cheminformatics microservices: {"chemicals": [{"sid": "ID1"}], "options": {...}}
Usage
generic_chemi_request(
query = NULL,
endpoint,
options = list(),
sid_label = "sid",
server = "chemi_burl",
auth = FALSE,
pluck_res = NULL,
wrap = TRUE,
array_payload = FALSE,
tidy = TRUE,
chemicals = NULL,
body = NULL,
content_type = "application/json",
paginate = FALSE,
max_pages = 100,
pagination_strategy = NULL,
...
)Arguments
- query
A character vector of identifiers (DTXSIDs, etc.). If NULL and chemicals is provided, the chemicals parameter is used instead.
- endpoint
The specific sub-path (e.g., "toxprints/calculate")
- options
A named list of parameters to be placed in the 'options' JSON field.
- sid_label
The key used for identifiers in the JSON body (usually "sid").
- server
Global environment variable name for the base URL (default: 'chemi_burl').
- auth
Boolean; whether to include the API key header. Defaults to FALSE.
- pluck_res
Optional character; the name of the field to extract from the JSON response.
- wrap
Boolean; whether to wrap the query in a
{"chemicals": [...], "options": ...}structure. Defaults to TRUE. If FALSE, sends a JSON array of objects like[{"sid": "ID1"}, ...]. Ignored if array_payload is TRUE.- array_payload
Boolean; if TRUE, creates a flat structure with identifiers as an array:
{"ids": ["ID1", "ID2"], "option1": "value1", ...}. When TRUE, sid_label is used as the array key name and options are merged at the top level. Takes precedence over wrap parameter. Defaults to FALSE.- tidy
Boolean; whether to convert the result to a tidy tibble. Defaults to TRUE.
- chemicals
Optional list of pre-resolved Chemical objects. Each element should be a list with fields like sid, smiles, casrn, inchi, inchiKey, name, mol. When provided, this takes precedence over the query parameter for building the chemicals payload.
- body
Optional explicit JSON request body. When supplied, normal chemical payload synthesis is bypassed and the body is encoded exactly as provided, preserving array order and duplicates.
- content_type
Expected response content type. JSON responses are parsed as lists; CSV and TSV responses are parsed as data frames.
- paginate
Boolean; whether to automatically fetch all pages. Defaults to FALSE. When TRUE, uses httr2::req_perform_iterative() to loop through pages.
- max_pages
Maximum pages to fetch when paginate=TRUE. Defaults to 100.
- pagination_strategy
Pagination strategy. For chemi search, usually "offset_limit" (body).
- ...
Named query parameters appended to the request URL.
