Learn R Programming

PubChemR (version 2.1.3)

get_pug_rest: Retrieve Data from PubChem PUG REST API

Description

This function sends a request to the PubChem PUG REST API to retrieve various types of data for a given identifier. It supports fetching data in different formats and allows saving the output.

Usage

get_pug_rest(
  identifier = NULL,
  namespace = "cid",
  domain = "compound",
  operation = NULL,
  output = "JSON",
  searchtype = NULL,
  property = NULL,
  options = NULL,
  save = FALSE,
  dpi = 300,
  path = NULL,
  file_name = NULL,
  ...
)

Value

An object of class `'PugRestInstance'` containing:

`success`

Logical value indicating if the request was successful.

`error`

If `success` is `FALSE`, a list containing error messages.

`result`

The content retrieved from the API; format depends on `output`.

`request_args`

A list of the arguments used in the request.

`fileDetails`

If `save` is `TRUE`, details about the saved file.

Arguments

identifier

A vector of identifiers for the query, either numeric or character. The type of identifier depends on the namespace parameter. **Note**: identifier must be provided; it cannot be NULL.

namespace

A character string specifying the namespace for the request.

Possible values include:

- cid: PubChem Compound Identifier (default)

- name: Chemical name

- smiles: SMILES string

- inchi: InChI string

- inchikey: InChIKey

- formula: Molecular formula

- sid: Substance ID

For more details, see the PUG REST API documentation.

domain

A character string specifying the domain for the request.

Possible values include:

- compound (default)

- substance

- assay

For more details, see the PUG REST API documentation.

operation

An optional character string specifying the operation for the request.

Possible values depend on the domain and namespace.

Examples include:

- property

- synonyms

- classification

- conformers

- cids, sids, aids (to get related compound, substance, or assay IDs)

If NULL (default), the default operation for the specified domain and namespace is used.

For a full list of operations, see the PUG REST API documentation.

output

A character string specifying the output format.

Possible values are:

- JSON (default)

- JSONP

- XML

- CSV

- SDF

- TXT

- PNG

For more details, see the PUG REST API documentation.

searchtype

An optional character string specifying the search type.

Possible values include:

- similarity

- substructure

- superstructure

If NULL (default), no search type is specified.

For more details, see the PUG REST API documentation.

property

An optional character string specifying the property or properties to retrieve.

This is typically used when operation is property.

Examples include:

- MolecularWeight

- MolecularFormula

- IUPACName

- InChI

- InChIKey

If NULL (default), all available properties are returned.

For a full list of properties, see the Compound Property Tables.

options

A list of additional options for the request.

Available options depend on the specific request and the API.

Examples include:

- For similarity searches: list(Threshold = 95)

- For substructure searches: list(MaxRecords = 100)

If NULL (default), no additional options are included.

For more details, see the Structure Search Operations section of the PUG REST API.

save

A logical value indicating whether to save the output as a file or image. Default is FALSE. If TRUE, the output will be saved to the path specified by path.

dpi

An integer specifying the DPI for image output when output is PNG. Default is 300.

path

A character string specifying the directory path where the output file will be saved if save is TRUE. If NULL (default), a temporary directory will be used.

file_name

A character string specifying the name of the file (without file extension) to save. If NULL (default), the file name is set as "files_downloaded".

...

Additional arguments passed to the underlying HTTP request functions.

Details

For more information on the possible values for parameters such as namespace, domain, operation, output, searchtype, and property, please refer to the PUG REST API documentation.

Examples

Run this code
result <- get_pug_rest(identifier = "2244", namespace = "cid", domain = "compound", output = "JSON")
pubChemData(result)


Run the code above in your browser using DataLab