5

在革命 R 企业控制台中,

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

生产

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

没有任何其他警告/错误/注释。所以,(即使 AFAIK 这条注释对于最终检查来说并不是那么重要),我想摆脱这个警告(因为我想把 .PDF 文件放到mypackage\inst\docR 之外生成的文件夹中)。

我的笔记本中安装了 Ghostscript。我通过以下方式获得帮助:

> 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] ""

我所做的(并再次出错)是:

> 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

深入后发现:[“这些错误发生在试图给一个不存在的变量赋值,或者R不能把它当作一个名字的时候。(名字是一个变量类型,它持有一个变量名."]

我基本上想做的是将我的 GS 可执行文件(C:\Program Files (x86)\gs\gs9.19\bin\gswin32c.exe)设置为“R_GSCMD”。任何帮助将不胜感激。

4

2 回答 2

6

在咨询?Sys.setenv时,它证实了我的期望,即电话应该是:

Sys.setenv(R_GSCMD = "C:\\Program Files (x86)\\gs\\gs9.19\\bin\\gswin32c.exe")
于 2016-05-12T21:57:58.977 回答
2

因为 gs 版本一直在变化,你可能会喜欢一个小 R 脚本!

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
于 2019-01-03T10:58:30.920 回答