Is it possible to include a Sexpr before the expression has been evaluated in Sweave / R ?

Posted by PaulHurleyuk on Stack Overflow See other posts from Stack Overflow or by PaulHurleyuk
Published on 2010-04-21T15:38:51Z Indexed on 2010/04/21 15:43 UTC
Read the original article Hit count: 255

Filed under:
|
|

Hello,

I'm writing a Sweave document, and I want to include a small section that details the R and package versions, platofrms and how long ti took to evalute the doucment, however, I want to put this in the middle of the document !

I was using a \Sexpr{elapsed} to do this (which didn't work), but thought if I put the code printing elapsed in a chunk that evaluates at the end, I could then include the chunk half way through, which also fails.

My document looks something like this

% 
\documentclass[a4paper]{article}
\usepackage[OT1]{fontenc}
\usepackage{longtable}
\usepackage{geometry}
\usepackage{Sweave}
\geometry{left=1.25in, right=1.25in, top=1in, bottom=1in}
\begin{document}

<<label=start, echo=FALSE, include=FALSE>>=
startt<-proc.time()[3]
@ 
Text and Sweave Code in here
% 
This document was created on \today, with \Sexpr{print(version$version.string)} running
 on a \Sexpr{print(version$platform)} platform. It took approx sec to process.
<<>>=
    <<elapsed>>
@ 
More text and Sweave code in here
<<label=bye, include=FALSE, echo=FALSE>>= 
odbcCloseAll()
endt<-proc.time()[3]
elapsedtime<-as.numeric(endt-startt)
@ 
<<label=elapsed, include=FALSE, echo=FALSE>>=
print(elapsedtime)
@ 
\end{document}

But this doesn't seem to work (amazingly !)

Does anyone know how I could do this ?

Thanks

Paul.

© Stack Overflow or respective owner

Related posts about r

    Related posts about sweave