Learn R Programming

PubChemR (version 2.1.3)

get_compounds: Retrieve Compounds from PubChem

Description

This function sends a request to the PubChem database to retrieve compound data based on specified parameters.

Usage

get_compounds(
  identifier,
  namespace = "cid",
  operation = NULL,
  searchtype = NULL,
  options = NULL
)

Value

An object of class 'PubChemInstanceList' and 'PC_Compounds' containing compound information from the PubChem database.

Arguments

identifier

A vector of positive integers (e.g., cid, sid, aid) or identifier strings (source, inchikey, formula). In some cases, a single identifier string (e.g., name, smiles, xref; inchi, sdf by POST only) is sufficient. **Note**: identifier must be provided; it cannot be NULL.

namespace

A character string specifying the namespace of the identifier.

Possible values include:

- cid: PubChem Compound Identifier (default)

- name: Chemical name

- smiles: SMILES string

- inchi: InChI string

- inchikey: InChIKey

- formula: Molecular formula

For more details, see the Input section of the PUG REST API.

operation

A character string specifying the operation to perform.

Possible values include:

- synonyms: Retrieve synonyms for the compounds.

- description: Retrieve compound descriptions.

- sids: Retrieve Substance IDs related to the compounds.

- aids: Retrieve Assay IDs related to the compounds.

- classification: Retrieve compound classification.

- cids: Retrieve Compound IDs (used when the input is not CID).

If NULL (default), the basic compound record is retrieved.

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

searchtype

An optional character string specifying the search type.

Possible values include:

- similarity

- substructure

- superstructure

- identity

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

For more details, see the Input section of the PUG REST API.

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.

Details

For more detailed information, please refer to the PubChem PUG REST API documentation.

See Also

retrieve, instance

Examples

Run this code
compound <- get_compounds(
  identifier = c("aspirin", "ibuprofen", "rstudio"),
  namespace = "name"
)

print(compound)

# Return results for selected compound.
instance(compound, "aspirin")
instance(compound, "rstudio")
# instance(compound, "unknown"). # returns error.

# Extract compound properties for the compound "aspirin".
# Use the 'retrieve()' function to extract specific slots from the compound list.
retrieve(instance(compound, "aspirin"), "props")

Run the code above in your browser using DataLab