I am showing a simple example here just to frame the question.
\documentclass{article}
\begin{document}
<<>>=
library('ggplot2')
dataset <- diamonds
@
\begin{table}[htbp]
\centering
\begin{tabular}{c|c|c|c}
\textbf{Name} & \textbf{Columns} \\\hline \hline
dataset & \Sexpr{length(colnames(dataset))} \\
\end{tabular}
\caption{Repeated table}
\end{table}
\end{document}
Now I am repeating this table (exact table) multiple times over the file. (Imagine replacing dataset with another set before calling this table).
\documentclass{article}
\begin{document}
<<>>=
library('ggplot2')
dataset <- diamonds;
@
\input{table-file.tex}
\end{document}
I am putting the entire tabular part into this file, and then input it several places. But I can't get this to work. I was wondering if this is possible? any better approaches to make this table "modular".
Thanks

