Sweave不显示加载消息

时间:2014-11-17 17:51:00

标签: r sweave

有一个related question询问相反的问题,就是如何在Sweave中抑制包的加载消息。我正在尝试显示消息,在编译pdf时我无法显示它。

部分消息显示使用knitr,但它只显示前两行,我不喜欢一般输出,所以我会坚持使用Sweave。

这是代码块:

<<results=verbatim, echo=TRUE, eval=TRUE>>=
library(tcpl)
@

这是包的onLoad函数(该函数使用packageStartupMessage函数来打印消息):

.onLoad <- function(libname, pkgname) {

  pkgd <- system.file(package = "tcpl")
  conf_file <- file.path(pkgd, "TCPL.config")

  if (file.exists(conf_file)) {

    source(conf_file, local = TRUE)

  } else {

    cat("## This file will be sourced every time the package is loaded.",
        "## When the package is installed this file is created with",
        "## the default settings for the example databases. You can change",
        "## the behavior for a single session using the 'setTcplOpts'", 
        "## function, or you can change the default load behavior using this",
        "## file. The file will not get overwritten unless the packge is re-",
        "## installed. You can also check the current settings using the",
        "## 'listTcplOpts' function. You can regenerate the default configure",
        "## file by deleting the TCPL.config file in the tcpl package",
        "## directory and reloading the package.",
        "",
        "######## Alter these values to change the default behavior ########",
        "",
        "DRVR = \"SQLite\" # the database (db) driver, 'SQLite' or 'MySQL'",
        "HOST = NA_character_ # the db server",
        "USER = NA_character_ # the db username",
        "PASS = NA_character_ # the db password for the given username",
        "DATA = file.path(pkgd, \"sql\", \"xmpl.sqlite\") # data db name",
        "CHEM = file.path(pkgd, \"sql\", \"xmpl.sqlite\") # chem db name",
        "LOG  = pkgd # filepath to write the run log into, default to pkg dir",
        "",
        "###################################################################",
        "",
        "",
        "tcplSetOpts(DRVR, USER, PASS, HOST, DATA, CHEM, LOG)",
        sep = "\n",
        file = conf_file)

    source(conf_file, local = TRUE)

  }

  v <- tcplListOpts()
  p <- names(v)
  pn <- sapply(p, nchar)
  sep <- sapply(pn, function(x) paste(rep(" ", 11 - x), collapse = ""))
  sep <- paste0(":", sep)
  cs <- sapply(seq_along(v), function(x) paste(p[x], v[[x]], sep = sep[x]))

  packageStartupMessage("tcpl loaded with the following settings:\n  ",
                        paste(cs, collapse = "\n  "),
                        "\nDefault settings stored in TCPL.conf. See ", 
                        "?tcplListOpts or ?tcplSetOpts for more information.")

}

我已经尝试了每个代码块设置的组合,我可以想到显示加载消息,它不会打印到pdf。我可以看到它在编辑文件时在控制台中打印出消息。

修改

同样的问题适用于data.table包的当前版本。

<<results=verbatim, echo=TRUE, eval=TRUE>>=
library(data.table)
@

不会在pdf中显示打印的消息,而是在干净的控制台中显示:

library(data.table)
# data.table 1.9.4  For help type: ?data.table
# *** NB: by=.EACHI is now explicit. See README to restore previous behaviour.

0 个答案:

没有答案