[Tex/LaTex] Modify R output in LaTeX

knitrr

I'm currently writing a paper for my bachelor thesis with LaTeX. I'm pretty new to LaTeX and I was wondering whether I can modify the R output in LaTeX.
For Example:
If I type in this:

<<echo=FALSE>>=
Data <- read.csv('./Daten/osp.csv')
nrow(Data)
@

I get the following output:

[1] 1000

and the output appears in a new line.
Is it possible to place the output in the same line where the text is and is it possible to get rid of the [1]?
Thank you very much!

Best Answer

Here is an example of getting the output out in the LaTeX output without any "R" stuff. %%% Save this file as filename.Rnw and then run knitr or sweave followed by pdflatex and a pdf viewer.

\documentclass[10pt,letterpaper]{article}

\begin{document}
hi 
<<echo=FALSE>>=
Data <- mtcars
nn<-nrow(Data)
@

Hello again, there are \Sexpr{nn} rows in the \textit{mtcars} data set

<<foo,echo=TRUE>>=
z <- 1+1
plot(cars)
@

The value of $z$ is \Sexpr{z}
\end{document}

I strongly recommend that you use knitr rather that sweave. There are more options available and you do not have to install any packages into the latex (*.Rnw) file. Documentation and information for knitr at http://yihui.name/knitr/

Here is the output of the above code. enter image description here