title: rmarkdown::render() output to stdout
body: <p>When I <code>render()</code> an <code>*.Rmd</code> file locally in RStudio, the output from the <code>render()</code> function is displayed in the console:</p>
  
  <p>Basic <code>.Rmd</code> file:</p>
  
  <pre><code>---
  title: "test"
  output: html_document
  ---
  
  ```{r setup, include=FALSE}
  
  sink("./output.txt", type = 'output')
  
  knitr::opts_chunk$set(echo = TRUE)
  ```
  
  ## Summary
  
  ```{r cars}
  summary(cars)
  ```
  
  ## Error
  
  ```{r}
  
  dbGetQuery()
  
  ```
  </code></pre>
  
  <p>To build:</p>
  
  <pre><code>library(rmarkdown)
  
  render('./test.rmd')
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="https://i.stack.imgur.com/mpta0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mpta0.png" alt="enter image description here"></a></p>
  
  <p>This is great when I'm creating reports locally and I can see the progress and errors thrown (if any). I need to monitor this output in stdout (or stderr) but I can't sink this output to that location because <a href="https://stackoverflow.com/questions/39131017/sink-wont-print-output-to-text-file-in-rmarkdown"><code>knitr</code> is using <code>capture.input</code> which uses <code>sink()</code> (see first comment)</a>. I even tried sinking to a file instead but though the file <code>output.txt</code> is created, there is nothing recorded in that file.</p>
  
  <p>This is an issue for me because I'm using <code>render()</code> in a Docker container and I can't send the chunk output from the <code>.Rmd</code> file in the Docker container to stderr or stdout. I need to monitor the chunk output for errors in the container R code inside the <code>.Rmd</code> file (to diagnose connection db connection errors) and sending those chunks to stdout or stderr is the only way to do that (without logging in to the container which, in my use case (i.e., deployed to AWS) is impossible) </p>
  
  <p>I've reviewed the <a href="https://yihui.org/knitr/options/#extracting-source-code" rel="nofollow noreferrer">knitr chunk options</a> and there doesn't seem to be any option I can set to force the chunk output to a file or to stdout or stderr.</p>
  
  <p>Is there some way I can write all of the chunk output to stdout or stderr inside of the <code>render()</code> function? <a href="https://stackoverflow.com/questions/39131017/sink-wont-print-output-to-text-file-in-rmarkdown">This several-years old question is similar to mine (if not identical) but the accepted answer does not fit my use case</a></p>