r - 在 Linux 中查找软件包的二进制文件
问题描述
我正在整理一个包,但是我似乎没有找到让包在系统中找到二进制文件的方法,请注意以下代码:
find_nim <- function(message=TRUE) {
nimexe <- ""
if (.Platform$OS.type == "unix") {
nimexe <- try(system2("which", "nim", stdout=TRUE))
if (message) message("Nim found at ", nimexe)
} else {
message("Unrecognized operating system.")
}
# if (nimexe=="") message("nim executable not found.\n Specify the location of your nim executable.")
return(nimexe)
}
这将在安装包时返回:
Warning in system2("which", "nim", stdout = TRUE) :
running command ''which' nim' had status 1
Nim found at
Error: package or namespace load failed for ‘nimrmarkdown’:
.onAttach failed in attachNamespace() for 'nimrmarkdown', details:
call: if (nimexe != "") {
error: argument is of length zero
相同的代码在 R 中本地工作。
- 在包开发中检查系统上的二进制文件的正确方法是什么?
解决方案
R 本身有Sys.which()
你可以使用:
R> Sys.which("emacs")
emacs
"/usr/bin/emacs"
R> Sys.which("does_not_exist")
does_not_exist
""
R>
编写 R 扩展手册也提到了它:
Usage of external commands should always be conditional on a test
for existence (perhaps using 'Sys.which'), as well as declared in
the 'SystemRequirements' field.
和
example in some locales. (Use e.g. 'capabilities()' or
'nzchar(Sys.which("someprogram"))' to test for features needed in
the examples wherever possible, and you can also use 'try()' or
推荐阅读
- node.js - 有什么方法可以自己使用 NodeJS 制作 GUI,而无需为其下载软件包?
- c# - 如何捕捉解码问题。System.FormatException:“Base-64 字符数组或字符串的长度无效。”
- javascript - Angular 9 - 错误类型错误:无法读取未定义的属性“名称”
- python - 遍历字典的 values()
- python - 如何在 Redis 中从 hmset() 切换到 hset()?
- powershell - 如何在同一文件夹中使用 powershell 生成 Zip
- jquery - 画布中精灵左右无限循环
- c++ - 在 BAZEL 中,有没有办法防止依赖 C/C++ 标头传播到依赖库?
- vuetify.js - 如何在多个启用的 v-select 组件中预先选择选项?
- python - Python中的真假测验功能