【问题标题】:Adding additional documentation to a package in R向 R 中的包添加附加文档
【发布时间】:2018-03-21 14:04:17
【问题描述】:

除了一个小插图,我希望在我的包中添加一个 PDF 格式的附加文档。当然,我可以将它复制到 inst/doc 目录,然后它将包含在包文档中。

但是,我想让用户更容易地显示这个文件。 edgeR 包的作者决定执行以下操作:主要用户手册以 PDF 格式分发(不是常规的小插图),作者包括一个名为 edgeRUsersGuide() 的函数,它通过以下代码显示 PDF:

edgeRUsersGuide <- function (view = TRUE) {
    f <- system.file("doc", "edgeRUsersGuide.pdf", package = "edgeR")
    if (view) {
        if (.Platform$OS.type == "windows") 
            shell.exec(f)
        else system(paste(Sys.getenv("R_PDFVIEWER"), f, "&"))
    }
    return(f)
}

它似乎工作。你觉得这样的做法合理吗?

还是应该使用其他东西?潜在地,以下代码也可以工作并且更健壮:

z <- list(PDF="edgeR.pdf", Dir=system.file(package="edgeR"))
class(z) <- "vignette"
return(z)

【问题讨论】:

  • 我只是把它作为另一个小插图。
  • 相信我,你不会的。我正在介绍非常大的数据集的案例研究。顺便说一下,这与 edgeR 的情况没有什么不同。

标签: r pdf documentation


【解决方案1】:

我的解决方案是模仿utils:::print.vignette()中的代码:

function(docfile) {

  ## code inspired by tools:::print.vignette
  pdfviewer <- getOption("pdfviewer")

  f <- system.file("doc", docfile, package = "tmod")
  if(identical(pdfviewer, "false")) 
    stop(sprintf("Cannot display the file %s", f))

  if (.Platform$OS.type == "windows" && 
      identical(pdfviewer, file.path(R.home("bin"), "open.exe"))) {
    shell.exec(f)
  }  else {
    system2(pdfviewer, shQuote(f), wait = FALSE)
  }

  return(invisible(f))
}

【讨论】:

    猜你喜欢
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多