From e23bd3cfdaf3211c8ed63219e23204697108cb38 Mon Sep 17 00:00:00 2001 From: Ranke Johannes Date: Wed, 22 Oct 2025 15:50:07 +0200 Subject: Improve messages and README Use README.rmd in order to be able to include demo code and output in the README. --- .Rbuildignore | 4 +- .gitignore | 1 + GNUmakefile | 13 +- R/chent.R | 15 ++- README.md | 132 ++++++++++++++------- docs/404.html | 8 +- docs/authors.html | 14 +-- docs/deps/bootstrap-5.3.1/bootstrap.min.css | 2 +- docs/deps/bootstrap-5.3.1/font.css | 48 ++++---- .../fonts/JTUSjIg1_i6t8kCHKm459W1hyzbi.woff2 | Bin 21288 -> 23836 bytes .../fonts/JTUSjIg1_i6t8kCHKm459WRhyzbi.woff2 | Bin 23516 -> 26476 bytes .../fonts/JTUSjIg1_i6t8kCHKm459WZhyzbi.woff2 | Bin 9512 -> 13020 bytes .../fonts/JTUSjIg1_i6t8kCHKm459Wdhyzbi.woff2 | Bin 27812 -> 70768 bytes .../fonts/JTUSjIg1_i6t8kCHKm459Wlhyw.woff2 | Bin 33092 -> 37828 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fABc4EsA.woff2 | Bin 9840 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fBBc4.woff2 | Bin 15920 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fBxc4EsA.woff2 | Bin 7016 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fCBc4EsA.woff2 | Bin 1500 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fCRc4EsA.woff2 | Bin 14968 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fChc4EsA.woff2 | Bin 11800 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmEU9fCxc4EsA.woff2 | Bin 5604 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fABc4EsA.woff2 | Bin 9576 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fBBc4.woff2 | Bin 15740 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fBxc4EsA.woff2 | Bin 7120 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fCBc4EsA.woff2 | Bin 1480 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fCRc4EsA.woff2 | Bin 15000 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fChc4EsA.woff2 | Bin 11796 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmSU5fCxc4EsA.woff2 | Bin 5468 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfABc4EsA.woff2 | Bin 9644 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfBBc4.woff2 | Bin 15860 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfBxc4EsA.woff2 | Bin 6936 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfCBc4EsA.woff2 | Bin 1432 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfCRc4EsA.woff2 | Bin 14684 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfChc4EsA.woff2 | Bin 11824 -> 0 bytes .../fonts/KFOlCnqEu92Fr1MmWUlfCxc4EsA.woff2 | Bin 5548 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu4WxKOzY.woff2 | Bin 7112 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu4mxK.woff2 | Bin 15744 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu5mxKOzY.woff2 | Bin 9628 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu72xKOzY.woff2 | Bin 15344 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu7GxKOzY.woff2 | Bin 11872 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu7WxKOzY.woff2 | Bin 5560 -> 0 bytes .../fonts/KFOmCnqEu92Fr1Mu7mxKOzY.woff2 | Bin 1484 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa0ZL7SUc.woff2 | Bin 17600 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7.woff2 | Bin 46704 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1pL7SUc.woff2 | Bin 22480 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa25L7SUc.woff2 | Bin 79940 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2JL7SUc.woff2 | Bin 27284 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2ZL7SUc.woff2 | Bin 12732 -> 0 bytes .../UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2pL7SUc.woff2 | Bin 10540 -> 0 bytes docs/deps/data-deps.txt | 4 +- docs/index.html | 12 +- docs/news/index.html | 10 +- docs/pkgdown.js | 8 ++ docs/pkgdown.yml | 6 +- docs/reference/chent-1.png | Bin 46084 -> 46142 bytes docs/reference/chent.html | 23 ++-- docs/reference/draw_svg.chent.html | 6 +- docs/reference/index.html | 6 +- docs/reference/pai-1.png | Bin 34451 -> 34388 bytes docs/reference/pai.html | 12 +- docs/reference/plot.chent-1.png | Bin 46084 -> 46142 bytes docs/reference/plot.chent.html | 12 +- docs/reference/ppp.html | 8 +- docs/reference/print.chent.html | 6 +- docs/reference/print.pai.html | 6 +- docs/reference/print.ppp.html | 6 +- docs/search.json | 2 +- docs/sitemap.xml | 1 + log/build.log | 1 - log/check.log | 4 +- log/test.log | 6 +- man/chent.Rd | 2 +- 72 files changed, 222 insertions(+), 156 deletions(-) delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fABc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fBBc4.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fBxc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fCBc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fCRc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fChc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmEU9fCxc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fABc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fBBc4.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fBxc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fCBc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fCRc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fChc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmSU5fCxc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfABc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfBBc4.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfBxc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfCBc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfCRc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfChc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOlCnqEu92Fr1MmWUlfCxc4EsA.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu4WxKOzY.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu4mxK.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu5mxKOzY.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu72xKOzY.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu7GxKOzY.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu7WxKOzY.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/KFOmCnqEu92Fr1Mu7mxKOzY.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa0ZL7SUc.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1pL7SUc.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa25L7SUc.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2JL7SUc.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2ZL7SUc.woff2 delete mode 100644 docs/deps/bootstrap-5.3.1/fonts/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2pL7SUc.woff2 diff --git a/.Rbuildignore b/.Rbuildignore index b0d9a9b..d94f770 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,7 +1,9 @@ ^chents_.*.tar.gz$ +^docs$ ^GNUmakefile$ ^log -^docs$ +^README.html$ +^README.rmd$ ^_pkgdown\.yml$ ^\.travis\.yml$ ^.*\.Rproj$ diff --git a/.gitignore b/.gitignore index 24c5c07..7452369 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ chents_*.tar.gz chents.Rcheck .Rproj.user .Rhistory +README.html diff --git a/GNUmakefile b/GNUmakefile index 6bbb53f..5c52c5b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -7,6 +7,9 @@ RBIN ?= $(shell dirname "`which R`") all: install +README.md: README.rmd + Rscript -e "rmarkdown::render('README.rmd', output_format = 'github_document', output_options = list(html_preview = FALSE))" + pkgfiles = DESCRIPTION \ .Rbuildignore \ DESCRIPTION \ @@ -26,7 +29,10 @@ $(TGZ): $(pkgfiles) "$(RBIN)/R" CMD build . 2>&1 | tee log/build.log pd: roxy - "$(RBIN)/Rscript" -e 'pkgdown::build_site()' + "$(RBIN)/Rscript" -e "pkgdown::build_site(run_dont_run = TRUE, lazy = TRUE)" + +pd_all: roxy + "$(RBIN)/Rscript" -e "pkgdown::build_site(run_dont_run = TRUE)" build: roxy $(TGZ) @@ -50,4 +56,7 @@ winbuilder: build @echo "Uploading to R-devel on win-builder" curl -T $(TGZ) ftp://anonymous@win-builder.r-project.org/R-devel/ -.PHONEY: roxy pd test quickcheck check install winbuilder +coverage: + "$(RBIN)/Rscript" -e "covr::report(file = 'docs/coverage/coverage.html')" + +.PHONEY: roxy pd test quickcheck check install winbuilder coverage diff --git a/R/chent.R b/R/chent.R index 5e0d663..941c445 100644 --- a/R/chent.R +++ b/R/chent.R @@ -155,13 +155,13 @@ chent <- R6Class("chent", #' Try to get chemical information from PubChem #' @param query Query string to be passed to [get_cid][webchem::get_cid] #' @param from Passed to [get_cid][webchem::get_cid] - try_pubchem = function(query, from = 'name') { - message("PubChem:") + try_pubchem = function(query = self$identifier, from = 'name') { + message("Querying PubChem for ", from , " ", query, " ...") if (missing(query)) query <- self$identifier pubchem_result = webchem::get_cid(query, from = from, match = "first") if (is.na(pubchem_result[[1, "cid"]])) { - message("Query ", query, " did not give results at PubChem") + message("Querying for ", query, " as ", from, " did not give results at PubChem") } else { self$get_pubchem(pubchem_result[[1, "cid"]]) } @@ -228,16 +228,15 @@ chent <- R6Class("chent", smiles_preferred_i <- min(match(available_smiles, smiles_preference)) smiles_preferred <- smiles_preference[smiles_preferred_i] - message("Trying to get chemical information from RDKit using ", + message("Get chemical information from RDKit using ", smiles_preferred, " SMILES\n", self$smiles[smiles_preferred]) self$rdkit <- list() self$mol <- rdkit_module$Chem$MolFromSmiles(self$smiles[1]) self$rdkit$mw <- rdkit_module$Chem$Descriptors$MolWt(self$mol) - if (!is.na(self$mw)) { + if (!is.null(self$mw) && !is.na(self$mw)) { if (round(self$rdkit$mw, 1) != round(self$mw, 1)) { - message("RDKit mw is ", self$rdkit$mw) - message("mw is ", self$mw) + warning("RDKit mw is ", self$rdkit$mw, " while mw is ", self$mw) } } else { self$mw <- self$rdkit$mw @@ -705,7 +704,7 @@ pai <- R6Class("pai", } if (!missing(iso) & bcpc) { - message("BCPC:") + message("Querying BCPC for ", identifier, " ...") bcpc_result = webchem::bcpc_query(identifier, from = "name") # Use first element of list, as we passed a query of length one diff --git a/README.md b/README.md index 766400d..1bea80d 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,108 @@ -# chents - -[![Online documentation](https://img.shields.io/badge/docs-jrwb.de-blue.svg)](https://pkgdown.jrwb.de/chents/) -[![R-Universe status](https://jranke.r-universe.dev/badges/chents)](https://jranke.r-universe.dev/chents) -[![Build Status](https://app.travis-ci.com/jranke/chents.svg?token=Sq9VuYWyRz2FbBLxu6DK&branch=main)](https://app.travis-ci.com/jranke/chents) -[![codecov](https://codecov.io/github/jranke/chents/branch/main/graphs/badge.svg)](https://app.codecov.io/gh/jranke/chents) -The R package **chents** provides some utilities for working with chemical -entities in R. + -## Features +# chents -- Some chemical information is retrieved from the PubChem website using the webchem -package -- If Python and RDKit (> 2015.03) are installed and configured for use with - 'reticulate', some basic chemoinformatics functions some additional chemical - information is computed and a 2D graph can be plotted -- Additional information can be read from a local .yaml file +[![Online +documentation](https://img.shields.io/badge/docs-jrwb.de-blue.svg)](https://pkgdown.jrwb.de/chents/) +[![R-Universe +status](https://jranke.r-universe.dev/badges/chents)](https://jranke.r-universe.dev/chents) +[![Code +coverage](https://img.shields.io/badge/coverage-jrwb.de-blue.svg)](https://pkgdown.jrwb.de/chents/coverage/coverage.html) + +The R package **chents** provides some utilities for working with +chemical entities in R. + +When first defining a chemical entity, some chemical information is +retrieved from the [PubChem](https://pubchem.ncbi.nlm.nih.gov/) website +using the [webchem](https://docs.ropensci.org/webchem/) package. + +``` r +library(chents) +caffeine <- chent$new("caffeine") +#> Querying PubChem ... +#> Trying to get chemical information from RDKit using PubChem SMILES +#> CN1C=NC2=C1C(=O)N(C(=O)N2C)C +``` -## Installation +If Python and [RDKit](https://rdkit.org) (\> 2015.03) are installed and +configured for use with the +[reticulate](https://rstudio.github.io/reticulate/) package, some +additional chemical information including a 2D graph are computed. + +The print method gives an overview of the information that was +collected. + +``` r +print(caffeine) +#> +#> Identifier $identifier caffeine +#> InChI Key $inchikey RYYVLZVUVIJVGH-UHFFFAOYSA-N +#> SMILES string $smiles: +#> PubChem +#> "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" +#> Molecular weight $mw: 194.2 +#> PubChem synonyms (up to 10): +#> [1] "caffeine" "58-08-2" +#> [3] "Guaranine" "1,3,7-Trimethylxanthine" +#> [5] "Methyltheobromine" "Theine" +#> [7] "Thein" "Cafeina" +#> [9] "Koffein" "Mateina" +``` -You can conveniently install chents from the repository kindly made available by the -R-Universe project: +There is a very simple plotting method for the chemical structure. +``` r +plot(caffeine) ``` -install.packages("chents", - repos = c("https://jranke.r-universe.dev", "https://cran.r-project.org")) + +![](man/figures/README-unnamed-chunk-4-1.png) + +Additional information can be (but is rarely ever) read from a local +.yaml file. This information can be leveraged e.g. by the +[PEC_soil](https://pkgdown.jrwb.de/pfm/reference/PEC_soil.html) function +of the ‘pfm’ package. + +If you have a so-called ISO common name of a pesticide active +ingredient, you can use the ‘pai’ class derived from the ‘chent’ class, +which starts with querying the [BCPC +compendium](http://www.bcpcpesticidecompendium.org/) first. + +``` r +lambda <- pai$new("lambda-cyhalothrin") +#> Querying BCPC for lambda-cyhalothrin ... +#> Querying PubChem ... +#> Trying to get chemical information from RDKit using PubChem SMILES +#> CC1([C@@H]([C@@H]1C(=O)O[C@@H](C#N)C2=CC(=CC=C2)OC3=CC=CC=C3)/C=C(/C(F)(F)F)\Cl)C +#> RDKit mw is 449.856 +#> mw is 449.8 +plot(lambda) ``` -In order to profit from the chemoinformatics, you need to install RDKit and its -python bindings. On a Debian type Linux distribution, just use +![](man/figures/README-unnamed-chunk-5-1.png) -``` -sudo apt install python3-rdkit -``` -If you use this package on Windows or MacOS, I would be happy to include -installation instructions here if you share them with me, e.g. via a Pull -Request. +## Installation -## Configuration of the Python version to use +You can conveniently install chents from the repository kindly made +available by the R-Universe project: -On Debian type Linux distributions, you can use the following line in your -global or project specific `.Rprofile` file to tell the `reticulate` package to -use the system Python version that will find the RDKit installed in the system -location. + install.packages("chents", + repos = c("https://jranke.r-universe.dev", "https://cran.r-project.org")) -``` -Sys.setenv(RETICULATE_PYTHON="/usr/bin/python3") -``` +In order to profit from the chemoinformatics, you need to install RDKit +and its python bindings. On a Debian type Linux distribution, just use -## Examples + sudo apt install python3-rdkit -Some examples are available from the -[reference on jrwb.de](https://pkgdown.jrwb.de/chents/reference). For example, -in the [example code section of the chent object docs](https://pkgdown.jrwb.de/chents/reference/chent.html#ref-examples) -you can see how to generate an R object for caffeine, show some of the information -retrieved from PubChem and plot it by virtue of RDKit. +If you use this package on Windows or MacOS, I would be happy to include +installation instructions here if you share them with me, e.g. via a +Pull Request. +## Configuration of the Python version to use +On Debian type Linux distributions, you can use the following line in +your global or project specific `.Rprofile` file to tell the +`reticulate` package to use the system Python version that will find the +RDKit installed in the system location. + Sys.setenv(RETICULATE_PYTHON="/usr/bin/python3") diff --git a/docs/404.html b/docs/404.html index ca1db25..9712405 100644 --- a/docs/404.html +++ b/docs/404.html @@ -8,8 +8,8 @@ Page not found (404) • chents - - + + @@ -20,7 +20,7 @@ chents - 0.3.7 + 0.4.0