Learn R Programming

PubChemR (version 3.0.0)

pc_request: Unified Transport Layer for PubChem Requests

Description

Executes PubChem API calls with unified handling for URL construction, retries, throttling, and optional cache replay.

Usage

pc_request(
  domain = "compound",
  namespace = "cid",
  identifier = NULL,
  operation = NULL,
  searchtype = NULL,
  output = "JSON",
  options = NULL,
  method = c("GET", "POST"),
  body = NULL,
  rate_limit = TRUE,
  timeout = NULL,
  retries = NULL,
  pause_base = NULL,
  pause_cap = NULL,
  user_agent = NULL,
  cache = FALSE,
  cache_dir = NULL,
  cache_ttl = NULL,
  force_refresh = FALSE,
  offline = NULL,
  ...
)

Value

An object of class `PubChemResult`.

Arguments

domain

PubChem domain.

namespace

PubChem namespace.

identifier

Identifier(s).

operation

Operation.

searchtype

Search type.

output

Output format.

options

Named list of query options.

method

HTTP method; `"GET"` or `"POST"`.

body

Optional POST body.

rate_limit

`TRUE` to use configured default, `FALSE` to disable, or numeric req/sec.

timeout

Timeout in seconds.

retries

Retry count.

pause_base

Retry base pause.

pause_cap

Retry max pause.

user_agent

User-agent string.

cache

Logical; enable memory+disk cache.

cache_dir

Cache directory.

cache_ttl

TTL in seconds.

force_refresh

Skip cache and refresh.

offline

`TRUE` to use cache-only replay mode (no network calls).

...

Additional arguments forwarded to `httr::RETRY`.

Details

`pc_request()` is the low-level engine behind higher-level `pc_*` helpers. When `offline = TRUE`, requests are served from cache only and return a structured failure object on cache misses.

Examples

Run this code
# Fast, network-free call: returns cache hit or structured cache-miss result.
res <- pc_request(identifier = 2244, offline = TRUE)
res$success

if (FALSE) {
pc_request(identifier = 2244)
}

Run the code above in your browser using DataLab