2

I am running logistic regression models and try to print out the output with stargazer in RMarkdown. I have applied dcolumn in my setup, but I still get "! LaTeX Error: Illegal character in array arg." when I try to knit the document to a pdf. I have tried to just copy in the LateX-code, but it also says I have an illegal character. Could someone help me to find the illegal character?

RMarkdown file:

title: "Tables and Figures"
author: "me"
date: "November 2019"
header_includes: - \usepackage{dcolumn}
output: pdf_documentclassoption: landscape




 ```   
 {r Regression results Q21 1, results='asis', echo=FALSE}

 Q21e_teaching99 <- glm(Q21e_teaching ~ Country + Field + typeposition + Gender + Age, data = 
 SurveyPHEC, family = binomial(link = "probit"))

 stargazer(Q21e_teaching99,  type="latex", align = TRUE)

 ```

LatexCode that this produces:

  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
 % Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at 
 fas.harvard.edu
 % Date and time: man., des 02, 2019 - 14.33.50
 % Requires LaTeX packages: dcolumn 
 \begin{table}[!htbp] \centering 
 \caption{} 
 \label{} 
 \begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} } 
 \\[-1.8ex]\hline 
 \hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & \multicolumn{1}{c}{Q21e\_teaching} \\ 
\hline \\[-1.8ex] 
CountryNorway & -0.255 \\ 
& (0.184) \\ 
& \\ 
CountryUnited Kingdom & 0.046 \\ 
& (0.195) \\ 
& \\ 
CountryNetherlands & 0.322^{**} \\ 
& (0.149) \\ 
& \\ 
CountryDenmark & 0.171 \\ 
& (0.165) \\ 
& \\ 
FieldPhysics & -0.109 \\ 
& (0.124) \\ 
& \\ 
typepositionSenior & 0.912^{***} \\ 
 & (0.119) \\ 
 & \\ 
GenderMale & 0.002 \\ 
 & (0.150) \\ 
 & \\ 
Age40 to 49 years & 0.283 \\ 
 & (0.179) \\ 
 & \\ 
Age50 to 59 years & 0.329^{*} \\ 
 & (0.185) \\ 
 & \\ 
Age60 years and more & 0.610^{***} \\ 
 & (0.192) \\ 
 & \\ 
Constant & -1.548^{***} \\ 
 & (0.217) \\ 
 & \\ 
\hline \\[-1.8ex] 
Observations & \multicolumn{1}{c}{788} \\ 
Log Likelihood & \multicolumn{1}{c}{-326.114} \\ 
Akaike Inf. Crit. & \multicolumn{1}{c}{674.227} \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 
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

R Markdown output

! LaTeX Error: Illegal character in array arg.

1 Answers1

3

The error indicates that the dcolumn package is not loaded. The reason it is not loaded are multiple syntax errors in your yaml header.

The following header should load the package (note the added line breaks):

---
title: "Tables and Figures"
author: "me"
date: "November 2019"
output:
  pdf_document:
    keep_tex: true
header-includes:
   - \usepackage{dcolumn}    
classoption: landscape
---