When I want to save my regression results with
stargazer(regressions[[reg]], out=myFile, out.header=FALSE
stargazer
keeps also displaying/printing the result into the console. As I'm iterating over dozens of results, this ruins my overview and the log. Is there any way to explicitly tell stargazer
not only to save the output to the file, but also not to print it additionally?
I'm on stargazer_5.1
.
You can write a function that captures the output of stargazer
and saves it to a file without any output to the console. For example, adapting code from this SO answer:
mod_stargazer <- function(output.file, ...) {
output <- capture.output(stargazer(...))
cat(paste(output, collapse = "\n"), "\n", file=output.file, append=TRUE)
}
Then, to run the function:
mod_stargazer(myfile, regressions[[reg]], header=FALSE)
append=TRUE
results in all your tables being saved to the same file. Remove it if you want separate files for each table.
well given the answer of eipi10, the only part you need is
bla <- capture.output(stargazer(..., out=output.file))
specifying the output file in stargazer and capture the output in something random, which you simply remove or overwrite for the next table. No need to define a new function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With