4

I teach econometrics using Rmarkdown on my university's rstudio pro server, running R 3.6.3. Whenever I run an rchunk using stargazer to display regression results, I get a preamble of errors before the table. Here is a copy and paste of the code and the exact results after running the code chunk:

lm.1 <- lm(mpg ~ cyl,data=mtcars)
stargazer(lm.1,type="text")

length of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changed

===============================================
                        Dependent variable:    
                    ---------------------------
                                mpg            
-----------------------------------------------
cyl                          -2.876***         
                              (0.322)          

Constant                     37.880***         
                              (2.074)          

-----------------------------------------------
Observations                    32             
R2                             0.726           
Adjusted R2                    0.717           
Residual Std. Error       3.206 (df = 30)      
F Statistic           79.560*** (df = 1; 30)   
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01

This error happens whether I use type= text, html, or latex.

Although the error does not show up in the knitted report, most of the work that the students do is simply running the r chunk. And, so every students gets a preamble of errors in bright red text before every regression results table they see. Not helpful in convincing them R and its useful packages are modern, stable, and professional tool for writing statistical reports.

Does anyone know what could be causing this error from stargazer and how to get rid of it?

EDIT: in reply to @J_F (thank you for your comment)

Here is the sessionInfo() output:

sessionInfo()

R version 3.6.3 (2020-02-29) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.4 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] stargazer_5.2.2

loaded via a namespace (and not attached): [1] compiler_3.6.3 tools_3.6.3 knitr_1.27 xfun_0.12

Here is the entirety of my .rmd file:

---
title: "stargazer test"
output: html_document
---
library(stargazer)
knitr::opts_chunk$set(echo = TRUE)
lm1 <- lm(mpg ~ cyl, data = mtcars)
stargazer(lm1,type="text")
B Haney
  • 41
  • 1
  • 3
  • What´s your desired output? What is `sessionInfo()` giving for details? I can not reproduce your described behaviour. – J_F Jun 14 '20 at 16:51
  • @J_F Thank you for your comment. Just to double check, are you just running the rchunk to try to recreate the error? That is the only time the error occurs. It does not show up when I knit. – B Haney Jun 14 '20 at 23:55

2 Answers2

1

I have been having this problem as well. Haven't been able to figure out the source of the message, but if you want to hide the warning messages you can turn them off for the whole document in the second chunk:

knitr::opts_chunk$set(echo = TRUE, warning = FALSE)

or by wrapping the stargazer call in suppressWarnings()

mdg
  • 39
  • 8
0

I get the same error, and I dont really know why. I figured out if I use the following in my code chunk, the stargazer table turns out ok when I knit.

{r results='asis'}