Reputation: 19405
Is there a simple way to automatically remove the
\begin{tabular}{@{\extracolsep{5pt}}lc}
and
\end{tabular}
lines at the beginning and end of a Stargazer LaTeX output?
Indeed, I just need the inside LaTeX code and removing those lines manually from the TeX file generated by stargazer is a complete loss of time...
Upvotes: 5
Views: 711
Reputation: 4200
Having the same issue, I ended up just adding some lines to my R
code after having created the table with stargazer
:
filename <- paste0("./my/path/", dplyr::last(list.files("./my/path/"))) # always loads the last file
lines <- readLines(filename) # read file
lines[1:4] <- "" # I wanted to replace the first four lines
lines[length(lines)] <- "" # as well as the last line
Hope this helps.
Upvotes: 0
Reputation: 15105
Each of the functions defined to create the LaTeX output in stargazer
are defined within the (internal) wrapper function .stargazer.wrap
. As such, it's not that easy to update the components automatically. You'll either have to make a copy of the package that you maintain locally, or edit the .stargazer.wrap
function every time you load the package.
Here's how to do the latter, following the guidelines from How do I override a non-visible function in the package namespace? (managing your own copy would entail something similar):
Load stargazer
:
> library(stargazer)
Edit the .stargazer.wrap
function inside the stargazer
namespace/package:
> fixInNamespace(".stargazer.wrap", pos="package:stargazer")
Find and remove at least rows 4206-4207 from the .data.frame.table.header
function:
These two lines are used to print the tabular
header.
Find and remove at least row 3385 in the .publish.table
function:
This line prints \end{tabular}
(plus a line break).
Upvotes: 3