Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print the data.table package's .onAttach messages with knitr

I have a bookdown rmd looking like...

Further introductory materials are offered when the package is loaded:

```{r dt-startup, echo=-1, message=TRUE, verbose=TRUE, hide=FALSE}
if ("data.table" %in% .packages()) detach("package:data.table")
library(data.table)
```

My intention was to show the reader the package's startup messages. However, they don't print. Is there some other chunk option to use here?

As you can see, I just threw several maybe-relevant chunk options at it to no good result. I'm not terribly familiar with management of output streams, so that's as far as I knew to go. I also tried calling directly with data.table:::.onAttach(), but no dice.

I'm not sure what else would be relevant here, but ...

  • Currently the package has not been loaded before this chunk. I just added the first line for robustness in case I rearrange the document.
  • My before_chapter_script contains nothing but knitr::opts_chunk$set(comment="#").
  • My knit header value is bookdown::render_book and the output is bookdown::html_book.
like image 643
Frank Avatar asked Mar 16 '17 17:03

Frank


1 Answers

Don't. Anything hacked in for this would be fragile and arguably not terribly useful.

Yihui Xie (knitr's author) makes a good case. My synopsis:

  • This is not useful. You're writing a tutorial, so why include dynamic content (that may change when the package changes)? Moreover, why not point to resources directly rather than to the list of resources printed there?
  • This is very hard. It is not just a matter of output streams. The messages don't print because they are walled behind an interactive() check. It's not obvious how this should be overridden and, supposing it could be done, what weird side effects that might introduce.
like image 84
Frank Avatar answered Nov 15 '22 05:11

Frank