aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2019-02-19 23:19:31 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2019-02-19 23:19:31 +0100
commitbfa20a8c262580e38d30cfa95e75d1b01b568d07 (patch)
treed316e76f437662eb193736af2b12bbf223db6e72 /R
parenta7e2c2008699b590325ccd848562881251676faf (diff)
Use rsvg instead of grConvert
as grConvert is not on CRAN
Diffstat (limited to 'R')
-rw-r--r--R/chent.R39
1 files changed, 18 insertions, 21 deletions
diff --git a/R/chent.R b/R/chent.R
index c80cf06..f6a8b09 100644
--- a/R/chent.R
+++ b/R/chent.R
@@ -28,6 +28,7 @@
#' @importFrom webchem get_cid cid_compinfo
#' @importFrom grImport PostScriptTrace readPicture
#' @importFrom yaml yaml.load_file
+#' @importFrom rsvg rsvg_ps
#' @field identifier The identifier that was used to initiate the object, with attribute 'source'
#' @field inchikey InChI Key, with attribute 'source'
#' @field smiles SMILES code, with attribute 'source'
@@ -193,26 +194,22 @@ chent <- R6Class("chent",
PythonInR::pyExec("d2d.DrawMolecule(mol)")
PythonInR::pyExec("d2d.FinishDrawing()")
self$svg <- PythonInR::pyGet("d2d.GetDrawingText()")
-
- if (!requireNamespace("grConvert")) {
- stop("grConvert is not available, self$Picture will not be created")
- } else {
- # Convert to PostScript, remembering size properties
- svgfile <- tempfile(fileext = ".svg")
- writeLines(self$svg, svgfile)
- psfile <- tempfile(fileext = ".ps")
- suppressMessages(grConvert::convertPicture(svgfile, psfile))
- ps_font_line <- grep("Tm$", readLines(psfile), value = TRUE)[1]
- ps_font_size <- gsub(" .*$", "", ps_font_line)
- self$Pict_font_size = as.numeric(ps_font_size)
-
- # Read in to create Picture
- xmlfile <- tempfile(fileext = ".xml")
- PostScriptTrace(psfile, outfilename = xmlfile)
- unlink(paste0("capture", basename(psfile)))
- self$Picture <- readPicture(xmlfile)
- unlink(c(xmlfile, psfile, svgfile))
- }
+ svgfile <- tempfile(fileext = ".svg")
+ psfile <- tempfile(fileext = ".ps")
+ writeLines(self$svg, svgfile)
+ rsvg::rsvg_ps(svgfile, psfile)
+
+ # Get size properties useful for plotting
+ ps_font_line <- grep("Tm$", readLines(psfile), value = TRUE)[1]
+ ps_font_size <- gsub(" .*$", "", ps_font_line)
+ self$Pict_font_size = as.numeric(ps_font_size)
+
+ # Read in to create Picture
+ xmlfile <- tempfile(fileext = ".xml")
+ PostScriptTrace(psfile, outfilename = xmlfile)
+ unlink(paste0("capture", basename(psfile)))
+ self$Picture <- readPicture(xmlfile)
+ unlink(c(xmlfile, psfile, svgfile))
},
get_chyaml = function(repo = c("wd", "local", "web"),
chyaml = paste0(URLencode(self$identifier), ".yaml")) {
@@ -610,7 +607,7 @@ rdkit_available <- function()
PythonInR::pyConnect()
}
sink(tempfile())
- try_rdkit <- try(PythonInR::pyImport("Chem", from = "rdkit"),
+ try_rdkit <- try(PythonInR::pyImport("Chem", from = "rdkit"),
silent = TRUE)
sink()
if (inherits(try_rdkit, "try-error")) {

Contact - Imprint