Reputation: 8374
I checked the function invisible
and quietly
from the purrr
package, but I couldn't work it out. I'm sorry if it has already been asked.
I have something like this:
library(forecast)
mod <- auto.arima(AirPassengers)
summary_mod <- summary(mod) # this always makes a print of the summary
rmse <- summary_mod[2]
I wanted to save the rmse from the model, but with summary
I can't find a way to kill the auto print function.
I've tried:
summary_mod <- invisible(summary(mod))
library(purrr)
summary_mod <- quietly(summary(mod))
I've found out that I can use:
accuracy(mod)[2]
# [1] 10.84619
But I was wondering if I can get a solution that suppress the print
function, just for possible future needs.
Upvotes: 2
Views: 1733
Reputation: 6132
Perhaps you could sink()
the output, like this:
mod <- auto.arima(AirPassengers)
sink("~temp.txt") #create temp file (you might replace ~ with desired working directory)
summary_mod <-summary(mod) #does not print anything now in R console, only in temp.txt file
sink(NULL) #use this to stop sinking the output
rmse <- summary_mod[2] #this still works now
Upvotes: 1
Reputation: 4980
You can use capture.output
.
summary_mod <- capture.output(summary(mod))[14]
Upvotes: 1