Stargazer: save to file, do not show in console

When I want to save the regression results with

stargazer(regressions[[reg]], out=myFile, out.header=FALSE 

stargazer also displays / prints the result in the console. As I repeat dozens of results, this ruins my review and journal. Is there a way to explicitly tell stargazer not only to save the output to a file, but not to print it additionally?

I am on stargazer_5.1 .

+7
r stargazer
source share
2 answers

You can write a function that displays stargazer output and saves it to a file without output to the console. For example, adapting the 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 causes all your tables to be saved in one file. Delete it if you need separate files for each table.

+6
source share

well received eipi10 answer, you only need a part

 bla <- capture.output(stargazer(..., out=output.file)) 

specifying the output file in stargazer and capturing the output in random order, which you simply delete or overwrite for the next table. There is no need to define a new function.

+1
source share

All Articles