【问题标题】:Finding a binary for a package in Linux在 Linux 中查找软件包的二进制文件
【发布时间】:2020-04-14 23:27:33
【问题描述】:

我正在整理一个包,但是我似乎没有找到让包在系统中找到二进制文件的方法,请注意下面的代码:

    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


    【解决方案1】:

    R 本身有 Sys.which() 你可以使用:

    R> Sys.which("emacs")
               emacs 
    "/usr/bin/emacs" 
    R> Sys.which("does_not_exist")
    does_not_exist 
                "" 
    R> 
    

    Writing R Extensions 手册也提到了这一点:

     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
    

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 1970-01-01
      • 2016-06-15
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多