Search code examples
rpdfstargazer

Stargazer Title Not Showing (Non-reproducible Error)


WARNING: I was not able to reproduce the error in a separate R/RStudio session, so I am hoping just to get some leads on trouble shooting my current .rmd script.

The Problem

All of a sudden, the stargazer title argument seemed to stop working. No matter what the title was or where I placed the argument within the function, it does not seem to work.

Additionally, and maybe related, I started getting this warning message:

the condition has length > 1 and only the first element will be used

Background

After @hpesoj626 helped me answer this question, the titles disappeared from my tables. Though not explicitly set in that example, stargazer's / LaTeX's default title was still being shown. After using the solution in that post, the titles disappeared.

I wanted to add a customized title to the tables by using the title = "" argument. This doesn't seem to help.

Attempts

  • I have tried using other character vector arguments to see if they work, like dep.var.labels = c(), and everything seems to work just fine.
  • I have tried reinstalling and updating the stargazer package.
  • I have tried removing all other arguments besides ... and title = ""
  • I tried different chunk options. (results='asis', echo=FALSE, etc.)
  • I have tried to restart R / Rstudio every way I know how
  • I have tried copying and pasting the .rmd file code to a completely separate script.
  • I was not able to find similar problems on SO.

As you will see in the below section, I have other packages loaded via namespace since I am loading .rda objects into my session using load(). I am loading glm() objects and ggplot() objects into my R/Rstudio session. Even when doing this in the example session, I have not able to reproduce the error.

Differences Between Linked Reproducible example and Actual Session

The only differences I can see between my example data and my actual data is that the generated LaTeX code for my actual data is missing this:

\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 

My actual data contains this:

the condition has length > 1 and only the first element will be used

And my actual sessionInfo() has a few more packages loaded via namespace:

R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] stargazer_5.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16      digest_0.6.15     grid_3.4.4        plyr_1.8.4        gtable_0.2.0      scales_0.5.0.9000 ggplot2_2.2.1     pillar_1.2.1      rlang_0.2.0.9001 
[10] lazyeval_0.2.1    labeling_0.3      tools_3.4.4       munsell_0.4.3     yaml_2.1.19       compiler_3.4.4    colorspace_1.3-2  knitr_1.20        tibble_1.4.2    

Do some of the packages loaded via namespace conflict with stargazer, LaTeX, or other packages?

Thanks

I know I wasn't able to provide the most information, given I wasn't able to reproduce the error myself, but I do appreciate any insight you might have on trouble shooting the problem. If you are able to provide some guidance, thank you.


Solution

  • After lots of trial and error, I was able to figure out a solution.

    I had not realized this, but including float = FALSE in the stargazer() function, removes this part of the generated LaTeX code:

    \begin{table}[!htbp] \centering 
      \caption{} 
      \label{}
    

    Which is where the title would go. But without using the float = FALSE, I wouldn't be able to position my tables where I wanted. And table.placement = "htbp" or any combination of those letters didn't position the tables properly and table.placement = "H" threw an error.

    Thanks to this post, I was able to put the following code in my YAML header and use table.placement = "H" and keep float = TRUE:

    ---
    title: "Title"
    author: "Name"
    output: pdf_document
    fig.caption: yes
    keep_tex: yes
    header-includes: \usepackage{float}
    ---
    

    Which places my tables in the appropriate place AND allows me to put titles on the tables.