Hi all

I want to count the number of citations contained within a .Rnw file and show the result as a tool tip.

My .Rnw file looks like this:

\section{Methods}

<<plot_mtcars>>=
plot(mtcars)
@

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat \citet{Author2014, AuthorEtAl2014}. \citet{AuthorAuthor2013} duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\section{Results}

<<plot_iris>>=
plot(iris)
@

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \citet*{Author1998} ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum \citep*{Somebody2014}.


Note that citation keys will be in one of these 3 formats: Author2014, AuthorAuthor2014 or AuthorEtAl2014. 

I would like to count the total number of citations within the .Rnw file and the number in each section. In above example there are 3 citations in the Methods section and 2 citations in the Results section.

Is this possible?

Thanks
Ross