6

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.

Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40

2 Answers2

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")
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • It worked. Perhaps, this could be given in R teaching materials where assignments are covered to get users accustomed to different assignment styles. – Erdogan CEVHER May 13 '16 at 04:19
  • 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. – IRTFM May 13 '16 at 05:12
  • 1
    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. – Erdogan CEVHER May 13 '16 at 07:10
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
TPArrow
  • 1,518
  • 18
  • 25