add library(knitr) before calling opts_chunk when replacing \SweaveOpts{} to opts_chunk$set()
apply the `chunk` hook to all engine output, per suggestion of Douglas Bates

he found the bug using a Julia code chunk

<<Jpreliminaries,engine='julia'>>=
using RDatasets,DataFrames
@

which generates empty output. If we do not apply the chunk hook, invalid LaTeX code will be produced in the end of this chunk:

\end{kframe}\begin{kframe}

i.e. the kframe environment is ended without being opened, and opened without being ended