Update: revised description here
This does not answer the exact question, but maybe the use case. I had a similar challenge recently: I wanted to combine the writing and analysis in one .rnw file, but my collaborators didn't want to use R/RStudio/GitHub/LaTeX.
So I decided to share a subfolder of my git repo with them via Dropbox. This folder contains three .docx files: introduction.docx, methods.docx, and discussion.docx (I write the results section within the .rnw file). The only catch is that they have to use some very basic LaTeX when writing, e.g., \subsection{heading} for headings, \cite{key} for references, ``quotes'', escaping \%, \$, and \&.
Back in the .rnw file, I convert the .docx files to .txt:
system("textutil -convert txt introduction.docx")
and then rename the file extension from .txt to .tex:
file.rename("introduction.txt", "introduction.tex")
Then outside of the R code chunks, I call in the .tex files with:
\input{introduction}
I posted a small example to GitHub.
\documentclass{article}
\makeatletter
\renewcommand{\@biblabel}[1]{\quad#1.}
\makeatother
\date{}
\bibliographystyle{plain}
\begin{document}
\begin{flushleft}
{\Large
\textbf{My Title}
}
\end{flushleft}
\section{Introduction}
% do not write in this section...let collaborators write in introduction.docx
<<intro, include=FALSE>>=
# assumes wd set to root folder collaborate
# convert docx to txt
system("textutil -convert txt introduction.docx")
# rename txt to tex
file.rename("introduction.txt", "introduction.tex")
@
% pull in introduction.tex
\input{introduction}
\section{Methods}
<<methods, include=FALSE>>=
system("textutil -convert txt methods.docx")
file.rename("methods.txt", "methods.tex")
@
\input{methods}
\section{Results}
<<results>>=
dat <- data.frame(x=runif(30, 0, 30))
mean <- mean(dat$x, na.rm=TRUE)
@
The mean is \Sexpr{round(mean, 1)}.
\section{Discussion}
<<discussion, include=FALSE>>=
system("textutil -convert txt discussion.docx")
file.rename("discussion.txt", "discussion.tex")
@
\input{discussion}
\bibliography{example.bib}
\end{document}
.Rtexformat, which keeps the R chunks as LaTeX-commented lines: see github.com/yihui/knitr-examples/blob/master/005-latex.Rtex - Ben Bolkerknitrchunks will auto-generate figure environments, captions, etc. for you; if you're willing to have the 'raw' version simply missing the figures (rather than having empty figures), you can use a chunk like<<myfigure,fig.cap="myfigure">>(which you would refer to via\ref{fig:myfigure}-- although your co-authors would end up with missing references). Could you just add a\or something to make the figure not completely empty? - Ben Bolker.Rtexsuggestion, you could setinclude=FALSEfor each of the figures and then insert them explicitly with your own calls to\begin{figure}; \includegraphics{}; \caption{\label{}}; \end{figure}. Your coauthors, when they don't have access to the figures created by knitr, can compile the document with placeholders for the figures by setting\usepackage[demo]{graphicx}in the document's preamble. With this approach, references will end up pointing to the appropriate figures, which will at least be identifiable by their captions. - Josh O'Brien\renewcommand{\Sexpr}{\texttt}maybe? - baptiste