#| include = FALSE

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

This vignette will demonstrate the basic functionality of cccapi and provides example code to work with SVG and MOL files.

Installing and loading cccapi

cccapi can be installed from GitHub with the following command:

#| eval = FALSE
install.packages("remotes")
remotes::install_github("ZeroPM-H2020/cccapi")

The package can be loaded like any other R package:

library(cccapi)

Searching for "atrazine"

You might want to search for a substance, say atrazine. This can be done with the get_search() function.

atz_src <- get_search("atrazine")

str(atz_src)

The returned list contains, among other things, the CAS Registry Number associated with atrazine in atz_src$results$rn. This can be used to retrieve more details.

Atrazine details

The details for the atrazine entry can be retrieved using the get_detail() function.

atz_dtl <- get_detail(atz_src$results$rn)

str(atz_dtl)

We now have access to the SVG file and know that a MOL file exists!

Saving and looking at SVG image files

The downloaded picture can saved with the writeLines() function.

writeLines(text = atz_dtl$image, con = "atrazine.svg")

The SVG can also be read with, for example, the image_read_svg() function of the magick package. This function requires the rsvg package.

atz_img <- magick::image_read_svg(atz_dtl$image)

atz_img

Writing MOL files

When a MOL file is available, it can be downloaded with the get_export() function. To write the MOL file, the writeLines() function can be used.

atz_mol <- get_export(atz_src$results$rn)

str(atz_mol)

writeLines(text = atz_mol, con = "atrazine.mol")

readLines(con = "atrazine.mol")


RaoulWolf/cccapi documentation built on March 6, 2023, 2:19 p.m.