2

There is a related question asking the oppostite question, being how to suppress the load message for a package in Sweave. I am trying to display the message and I cannot get it to show when compiling the pdf.

A partial message shows up with using knitr, but it only shows the first two lines and I do not like the general output so I am going to stick with Sweave.

Here is the code chunk:

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

Here is the onLoad function for the package (the function utilizes the packageStartupMessage function to print the message):

.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.")

}

I have tried every combination of code chunk settings I can think of to display the load message, and it will not print to the pdf. I can see it print the message out in the console when the file is being weaved.

EDIT

The same problem holds true for the current release of the data.table package.

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

Does not show the printed message in the pdf, but does in a clean console:

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.
Community
  • 1
  • 1
dayne
  • 7,504
  • 6
  • 38
  • 56
  • Where did you get **tcpl**? It's not on CRAN, so it's hard to make this reproducible. – Thomas Nov 17 '14 at 18:02
  • @Thomas I apologize. I am in the process of writing the package. I was hoping someone might have a general answer. You can find a beta copy of the package (obviously without the vignette) at epa.gov/ncct/toxcast/data.html – dayne Nov 17 '14 at 19:23
  • @Thomas I thought the problem might be specific to how I wrote the onLoad package, but the load message for data.table gets stripped out as well. – dayne Nov 17 '14 at 19:50
  • 1
    Yes, this is a general issue with Sweave not printing messages in output. The various solutions on this site suggest just switching to knitr. You should be able to mimic the look of Sweave output using knitr, so that's probably the way to go. – Thomas Nov 17 '14 at 19:51
  • @Thomas Thanks. Guess I will move on. – dayne Nov 17 '14 at 19:54

0 Answers0