I just started using the stargazer
package to make regression tables in R, but can't figure out how to write table output to a .tex file without either floating or document environments (and preamble in the case of the document environment). That is, I just want the tabular environment. My work flow is to keep the table floating environment - and the associated captions and labels -- in the body of the paper and link to the table's tabular environment with \input{}
.
Is this possible?
# bogus data
my.data <- data.frame(y = rnorm(10), x = rnorm(10))
my.lm <- lm(y ~ x, data=my.data)
# if I write to file, then I can omit the floating environment,
# but not the document environment
# (i.e., file contains `\documentclass{article}` etc.)
stargazer(my.lm, float=FALSE, out="option_one.tex")
# if I write to a text connection with `sink`,
# then I can omit both floating and document environments,
# but not commands
# (i.e., log contains `sink` and `stargazer` commands)
con <- file("option_two.tex")
sink(con)
stargazer(my.lm, float=FALSE)
sink()