You can use the sink()
function in R. It will divert all R console output between the first and second call of sink()
to a file that you specify. Here is an example using a linear model fitted to the iris
data set.
fit <- lm(Petal.Length ~ Sepal.Length, data = iris)
sink(file = "lm_output.txt")
summary(fit)
sink(file = NULL)
This will create a file lm_output.txt in your working directory containing the output of summary(fit)
.