Apology at first if this question has been asked or the sample is not reproducible. I'm totally new to LaTex and happy to take any advice.
I am working on my thesis on a .tex LaTex template given by the university, and I just saved it as a .rnw file since I would like to include some R results. Before I added code, the file can knitr well and generate a pdf.
\documentclass[master,tocprelim]{cornell}
\usepackage{graphicx,pstricks}
\usepackage{graphics}
\usepackage{moreverb}
\usepackage{subfigure}
\usepackage{epsfig}
\usepackage{hangcaption}
\usepackage{txfonts}
\usepackage{palatino}
\graphicspath{ {figures/} }
\begin{document}
He said it is cool\cite{tkh1998}.
<<code, echo=FALSE, message=FALSE, warning=FALSE>>=
library(kableExtra)
library(tidyverse)
library(dplyr)
data = data.frame(matrix(rnorm(20, 10, 2), ncol=4))
kable(data, 'latex', caption = 'Time series Errors',
longtable = T, booktabs = T) %>%
kable_styling(latex_options = c("striped", "hold_position", "repeat_header"))
@
\appendix
%\bibliography{LR}
\end{document}
(I don't know how to include reference in the .rnw file, but my .bib file include this citation:
@ARTICLE{tkh1998,
author={ {Tin Kam Ho}},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
title={The random subspace method for constructing decision forests},
year={1998},
volume={20},
number={8},
pages={832-844},
keywords={pattern classification;trees (mathematics);decision theory;random processes;learning (artificial intelligence);random subspace method;decision forests;decision trees;overfitting;maximum accuracy;decision tree based classifier;generalization accuracy;feature vector;classification accuracy;Decision trees;Classification tree analysis;Training data;Clustering algorithms;Tin;Stochastic systems;Binary trees;Support vector machines;Support vector machine classification},
doi={10.1109/34.709601},
ISSN={0162-8828},
month={Aug},}
However, after I added:
<<code, echo=FALSE, message=FALSE, warning=FALSE>>=
library(kableExtra)
library(tidyverse)
library(dplyr)
data = data.frame(matrix(rnorm(20, 10, 2), ncol=4))
kable(data, 'latex', caption = 'Time series Errors',
longtable = T, booktabs = T) %>%
kable_styling(latex_options = c("striped", "hold_position", "repeat_header"))
@
This file cannot be knitr anymore. It produced errors including "citation tkh1998 undefined on input line 86" (I don't even have line 86!!), "Incompatible color definition on input line 89", "Undefined control sequence".
I appreciate any suggestion about integrating LaTeX output and R results together (especially KableExtra outputs), shall I mainly write in .tex or .rnw, etc.

.bibfile for bibliography? For instance,\bibliography{job}wherejob.bibis located under the same folder as.rnwfile. (When I made above changes on your basis, it generated an error sayingundefined control sequence... – Rachel Zhang Jun 29 '19 at 14:41\begin{filecontents}\end{filecontents}to make the example complete and portable. You can remove this part since you already have your.bibfile. You can have any*.bibfile in your working directory and just reference that file usingaddbibresource{bibfilename.bib}. Theundefined control sequenceindicates a command is not recognized. Was there additional information with that error to provide a clue about what command was not recognized? Can you compile the example exactly as posted, with just this one bibentry? – Ross Jun 29 '19 at 16:04