title: Using knit_child in RStudio to manage thesis .Rnw chapters in master .Rnw. \ref and \label don't work now
body: <p>To say that I am a LaTeX amateur is an understatement, though by some miracle, I am managing to write my thesis in it. I am using RStudio to write and compile my thesis, due to all of my analysis being done in R and wanting the ability to insert dynamic plots etc. </p>
  
  <p>As my thesis has increased in size, I wanted to break the chapters off into sub .Rnw files so that I could work on each chapter independently (with my need for R code within each chapter ruling out using .tex files). The only way I could get this to work, was using \Sexpr{knit_child('chapter.Rnw')}. I weave my files using knitr rather than Sweave as again, that is the only I can get it to compile correctly. Unfortunately, I've never managed to understand why!</p>
  
  <p>Nevertheless, this is working very nicely, is much easier to manage and my plots and R code are compiling correctly, but my previously functioning \ref and \label commands no longer work. Well, they work within a chapter, but not between them. </p>
  
  <p>I include my main document here and the latex commands that I think are relevant to my question. I have googled this all morning, but am getting nowhere alone. </p>
  
  <pre><code>\documentclass[12pt]{report} %What kind of document 
  \usepackage{titlesec} %can actually name chapters rather than having "Chapter 1" etc
  \usepackage[backend=bibtex,style=authoryear-comp,sorting=nyt,maxcitenames=2,url=false]{biblatex}
  \bibliography{library}
  
  % ----------- KNITR SETUP ------------------------
  &lt;&lt;setup, include=FALSE, cache=FALSE, echo=FALSE&gt;&gt;=
  opts_chunk$set(fig.path='figures/plots-', fig.align='center', fig.show='hold', eval=TRUE, echo=TRUE)
  options(replace.assign=TRUE,width=80)
  # setwd("C:/Users/cainswor/Box Sync/Imperial/Reports/Thesis")
  setwd("D:/BoxSync/BoxSync/Reports/Thesis")
  data_loc &lt;- "D:/BoxSync/BoxSync/Reports/Thesis/Data for Thesis"
  Sys.setenv(TEXINPUTS=getwd(),
             BIBINPUTS=getwd(),
             BSTINPUTS=getwd())
  
  x &lt;- c("shiny","flowViz","nls2","plyr","RColorBrewer","abind","MASS","gplots","hexbin",
         "data.table","fastmatch","stringr","hypergeo","rgl","mclust","knitr","dbscan")
  lapply(x, require, character.only=T)
  # Sweave2knitr('ThesisSecondDraft.Rnw')
  @
  
  \begin{document}
  
  \Sexpr{knit_child('Th1_Introduction.Rnw')}
  
  \part{The Experiment}
  
  \Sexpr{knit_child('Th2_Characterisation.Rnw')}
  
  \end{document}
  </code></pre>