diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2017-06-13 16:05:39 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2017-06-13 16:05:39 +0200 |
commit | 3f82707cd1e974848185b1141c69734e2573594d (patch) | |
tree | 42b968e860f8748280d2d217a1b24831f9d06970 /R | |
parent | f5b36dc73e7778091a08eaed51fd9d4f8677fbc1 (diff) |
Make grConvert optional as it vanished on Windows
Diffstat (limited to 'R')
-rw-r--r-- | R/chent.R | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -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"), |