From 3f82707cd1e974848185b1141c69734e2573594d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 13 Jun 2017 16:05:39 +0200 Subject: Make grConvert optional as it vanished on Windows --- R/chent.R | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'R/chent.R') diff --git a/R/chent.R b/R/chent.R index 192c6df..3e89e14 100644 --- a/R/chent.R +++ b/R/chent.R @@ -191,22 +191,26 @@ chent <- R6Class("chent", PythonInR::pyExec("d2d.DrawMolecule(mol)") PythonInR::pyExec("d2d.FinishDrawing()") self$svg <- PythonInR::pyGet("d2d.GetDrawingText()") - svgfile <- tempfile(fileext = ".svg") - writeLines(self$svg, svgfile) - - # Convert to PostScript, remembering size properties - 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)) + + 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)) + } } }, get_chyaml = function(repo = c("wd", "local", "web"), -- cgit v1.2.1