2

This thread is the continua of the thread How to save R xtable(data.frame) output in .tex document? but with the package stargazer where the approach proposed for xtable does not work. Code

DF <- head(iris)
library("stargazer") # https://stackoverflow.com/a/9274146/54964
filename.tex <- paste("/home/masi/text.tex")
DF.tex <- stargazer(DF)
print(DF.tex, file = "/home/masi/filename.tex", compress = FALSE) # https://unix.stackexchange.com/a/368184/16920

Output: no .tex file

R: 3.4.0 (backports)
OS: Debian 8.7

2

You have to capture the console output with capture.output():

writeLines(capture.output(stargazer(DF)), filename.tex)
  • Do you have any idea why those two packages differ so much in giving out the outputs? – Léo Léopold Hertz 준영 Jun 1 '17 at 13:53
  • 1
    The xtable package contains a S3 print method for xtable objects (xtable::print.xtable). stargazer doesn't have a print method. – rcs Jun 1 '17 at 13:57
  • Does it mean that this approach would work also with xtable? – Léo Léopold Hertz 준영 Jun 1 '17 at 13:59
  • 1
    yes, writeLines(capture.output(xtable::print.xtable(xtable::xtable(iris))), "test.tex") – rcs Jun 1 '17 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.