“如何修复”;找不到GhostScript可执行文件来运行大小缩减检查;在R中签入包时出错?

“如何修复”;找不到GhostScript可执行文件来运行大小缩减检查;在R中签入包时出错?,r,ghostscript,setenv,R,Ghostscript,Setenv,在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 没有任何其他警告/错误/注释。所以,(尽管这张便条对最终的检查来说并不重要),我还是想摆脱这个警

在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
没有任何其他警告/错误/注释。所以,(尽管这张便条对最终的检查来说并不重要),我还是想摆脱这个警告(因为我想把.PDF文件放到在R之外生成的
mypackage\inst\doc
文件夹中)

我的笔记本中安装了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”)关于咨询
?Sys.setenv
它证实了我的期望,即调用应该是:

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

因为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

成功了。也许,这可以在R教材中给出,其中涵盖了作业,以让用户习惯不同的作业风格。我同意R函数看起来确实有些“不规则”。使用
选项进行的系统设置对我来说也总是很奇怪。每次我都需要检查帮助页面。将“C:\Program Files(x86)\gs\gs9.19\bin\”添加到系统环境变量中的“Path”变量中,永久性地解决了我的“找不到GhostScript可执行文件…”问题(对于每个R会话)。要添加,我做了以下操作:我的计算机-右键单击-属性-高级系统设置-系统属性窗口中的高级选项卡-环境变量-单击系统变量-编辑-添加中的“路径”;C:\Program Files(x86)\gs\gs9.19\bin\“到行末。
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