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.
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,
...
)
An object of class `'PugRestInstance'` containing:
Logical value indicating if the request was successful.
If `success` is `FALSE`, a list containing error messages.
The content retrieved from the API; format depends on `output`.
A list of the arguments used in the request.
If `save` is `TRUE`, details about the saved file.
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
.
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.
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.
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.
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.
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.
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.
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.
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
.
An integer specifying the DPI for image output when output
is PNG
. Default is 300
.
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.
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.
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.
result <- get_pug_rest(identifier = "2244", namespace = "cid", domain = "compound", output = "JSON")
pubChemData(result)
Run the code above in your browser using DataLab