Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stargazer: Save to file, don't show in console

Tags:

r

stargazer

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.

like image 594
FooBar Avatar asked May 12 '15 15:05

FooBar


2 Answers

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.

like image 71
eipi10 Avatar answered Oct 16 '22 09:10

eipi10


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.

like image 27
wesselnv Avatar answered Oct 16 '22 10:10

wesselnv