This prints the LaTeX markup in our R session. The Stargazer docs say:

‘stargazer’ uses ‘cat()’ to output LaTeX code for the table. To
allow for further processing of this output, ‘stargazer’ also
returns the same output invisibly as a character string vector.
You can include the produced tables in your paper by inserting
‘stargazer’ output into your publication's TeX source.

So, according to this there’s no built-in way to get stargazer to write its output directly to a file. One option would be to use R’s sink() to divert the output from stargazer:

> sink("output-from-sink.tex")> stargazer(attitude)> sink()

This gives us a file named output-from-sink.tex which we can include in documents.

That works fine, we can create as many separate files as we need. However, it might be nice to create a single file with multiple LaTeX snippets in it, referenced by name.

To do this we create a list and add named elements to the list containing output from running stargazer: