--- title: "Reproducible Cached Retrieval and Batching" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Reproducible Cached Retrieval and Batching} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ``` This vignette shows reproducible high-throughput retrieval using: - `pc_config()` for centralized policy. - `pc_request(..., cache = TRUE)` deterministic caching. - `pc_batch()` chunked execution. ```{r setup} library(PubChemR) library(tibble) library(dplyr) ``` ## Configure defaults ```{r} cfg <- pc_config( rate_limit = 5, retries = 3, timeout = 60 ) cfg ``` ## Clear cache for a clean run ```{r} pc_cache_clear() ``` ## Cached property retrieval ```{r eval=FALSE} first <- pc_property( identifier = c(2244, 3672, 2519), properties = c("MolecularWeight", "XLogP", "TPSA"), namespace = "cid", cache = TRUE ) second <- pc_property( identifier = c(2244, 3672, 2519), properties = c("MolecularWeight", "XLogP", "TPSA"), namespace = "cid", cache = TRUE ) # second$from_cache is expected to be TRUE as_tibble(second) ``` ## Chunked batch execution ```{r eval=FALSE} ids <- c("aspirin", "ibuprofen", "caffeine", "acetaminophen", "naproxen") batch <- pc_batch( ids = ids, fn = function(chunk_ids) { pc_identifier_map( identifier = chunk_ids, namespace = "name", to = "cids", domain = "compound", cache = TRUE ) }, chunk_size = 2 ) batch as_tibble(batch) ```