Q: Write summary of fit in pdf file or similar I'm doing a linear fitting on many datasets in a loop and plotting the results in a pdf file. Is it possible to directly save the output of summary(fit) in the same pdf file instead of observing the summaries of about 100 datasets through the console?
  LMmodel <- y ~ x
  fit <- lm(LMmodel, data = Dataset)

  pdf(file = OutputFile, width = 10, height = 6, paper = "a4r")

  xLim = range(x)
  yLim = range(y)

  plot(x, y, type = "p", xlim = xLim, ylim = yLim,
       main = plotTitle, xlab = "x [m]", ylab = "y [dB]",
       pch = 20, cex = .9)
  regLine(fit, col=palette()[2], lwd=2, lty=1)
  grid(lwd = 1.5)

  plot(density(residuals(fit)), main = "Density Plot of the Residuals"))

  dev.off()
  graphics.off()
  return(summary(fit))


A: I really recommend Knitr with Rstudio to generate Report. 
Here I use you code to generate a pdf in 3 simple steps. I assume you have Rstudio installed.


*

*I create a new R sweave file ( using the menu)

*Where I insert 2 chuncks (using the Chunks at right)
<<myplot,echo=FALSE,fig=TRUE>>=
library(car)
x <- rnorm(n=20,mean=30,sd=20)
y <- rnorm(n=20,mean=180,sd=10)
Dataset <- data.frame(x=x,y=y)
LMmodel <- y ~ x
fit <- lm(LMmodel, data = Dataset)
xLim = range(x)
yLim = range(y)
plot(x, y, type = "p", xlim = xLim, ylim = yLim,
    main = "plotTitle", xlab = "x [m]", ylab = "y [dB]",
    pch = 20, cex = .9)
regLine(fit, col=palette()[2], lwd=2, lty=1)
grid(lwd = 1.5)
plot(density(residuals(fit)), main = "Density Plot of the Residuals")
@

the summary is : 
    <<mysummary>>=
    print(summary(fit))
    @



*

*You generate a pdf file using the compile PDF button.


You can insert what you want between the summary and the plots to build complex reports.
