How to fix "Unable to find GhostScript executable to run checks on size reduction" error upon package check in R?
Asked Answered
A

2

8

In Revolution R Enterprise console,

devtools::check("C:/Users/User/Documents/Revolution/mypackage")

produced

checking sizes of PDF files under 'inst/doc' ... NOTE
Unable to find GhostScript executable to run checks on size reduction

with no any other warnings/errors/notes. So, (even though AFAIK this note is not that much important for eventual check), I wanted to get rid of this warning (since I wanna put .PDF files into mypackage\inst\doc folder produced outside of R).

I have Ghostscript installed in my notebook. I got helped via:

> help("R_GSCMD")
R_GSCMD: Optional. The path to Ghostscript, used by dev2bitmap, bitmap and embedFonts. 
Consulted when those functions are invoked. 
Since it will be treated as if passed to system, spaces and shell metacharacters should be escaped.


> Sys.getenv("R_GSCMD")
[1] ""

What I did (and took error again) is:

> Sys.setenv("R_GSCMD") <- "C:\\Program Files (x86)\\gs\\gs9.19\\bin\\gswin32c.exe"
Error in Sys.setenv("R_GSCMD") <- "C:\\Program Files (x86)\\gs\\gs9.19\\bin\\gswin32c.exe" : 
  target of assignment expands to non-language object

Upon deepening, I found: ["These errors occur when one tries to assign a value to a variable that doesn't exist, or that R can't treat as a name. (A name is a variable type that holds a variable name."]

What I am basically trying to do is to set my GS executable (C:\Program Files (x86)\gs\gs9.19\bin\gswin32c.exe) to "R_GSCMD". Any help would be greatly appreciated.

Antimonic answered 12/5, 2016 at 21:21 Comment(0)
C
6

On consulting ?Sys.setenv it confirms my expectation that the call should instead be:

Sys.setenv(R_GSCMD = "C:\\Program Files (x86)\\gs\\gs9.19\\bin\\gswin32c.exe")
Calipee answered 12/5, 2016 at 21:57 Comment(3)
It worked. Perhaps, this could be given in R teaching materials where assignments are covered to get users accustomed to different assignment styles.Antimonic
I agree that R functions do seem somewhat "irregular". The system setting done with options always seemed odd to me as well. I need to check the help pages every time.Calipee
Adding "C:\Program Files (x86)\gs\gs9.19\bin\" to "Path" variable in System Environment Variables solved my "Unable to find GhostScript executable..." issue permanently (for every R session). To add, I did this: My Computer - rightclick - properties - Advanced system settings - Advanced tab in System Properties window - Environment variables - Click "Path" in System variables - Edit - add ";C:\Program Files (x86)\gs\gs9.19\bin\" to the end of line.Antimonic
F
3

Because the gs versions change all the time, you may like a little R script for it!

system.partition = 'c:'
dirs = c('Program Files', 'Program Files (x86)')
for (dir in dirs) {
    dir.list = list.dirs(file.path(system.partition, dir), recursive = FALSE)
    GsinList = grepl(pattern = 'gs', x = dir.list)
    if (sum(GsinList) > 0) {
        gsDirectory = which(GsinList == TRUE)
        GsExeFiles = list.files(
            dir.list[gsDirectory],
            recursive = TRUE,
            pattern = 'gswin',
            include.dirs = TRUE,
            full.names = TRUE
        )[1]
        message('Gs found! ~> ',GsExeFiles)
        Sys.setenv(R_GSCMD = GsExeFiles)
        break
    }
}


Gs found! ~> c:/Program Files/gs/gs9.21/bin/gswin64.exe
Flesher answered 3/1, 2019 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.