简体   繁体   中英

How to fix “Unable to find GhostScript executable to run checks on size reduction” error upon package check in R?

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.

在咨询?Sys.setenv它确认了我的期望,该电话应改为:

Sys.setenv(R_GSCMD = "C:\\Program Files (x86)\\gs\\gs9.19\\bin\\gswin32c.exe")

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM