Learn R Programming

PubChemR (version 3.0.0)

pc_response: Normalize an HTTP Response Into a Typed PubChem Result

Description

Parses PubChem response payloads and standardizes them into a typed `PubChemResult` object with success, error, and metadata fields.

Usage

pc_response(response, request = list())

Value

An object of class `PubChemResult`.

Arguments

response

A `httr` response object or raw text.

request

Request metadata list.

Details

JSON and plain-text payloads are supported. Fault payloads and non-2xx HTTP statuses are normalized into structured error entries rather than raising immediate transport exceptions.

Examples

Run this code
ok <- pc_response('{"IdentifierList":{"CID":[2244]}}', request = list(domain = "compound"))
ok$success

fail <- pc_response('{"Fault":{"Code":"PUGREST.NotFound","Message":"Not found"}}')
fail$success

Run the code above in your browser using DataLab