How to fix the warning "label `' multiply defined"

14k views Asked by At

I am running an lm regression in r, where there are categorical variables and numerical variables. I am usig knitr to compile the Rnw file to make a pdf. I use texreg to make latex regression tables. But when I do the compiling, it reported that lots of lines "Label `' multiply defined". Is it a must that we should assign label to each variable in the regression? But for those factor variables, I tried to assign label, like label(data$var) <- "name", then the warning is "label" command cannot be applied to the class of factor. Now I am really confused. Can anyone help me with this?

3

There are 3 answers

0
Philip Leifeld On

You are using the texreg package to create multiple tables for inclusion in a LaTeX document. When you use the texreg function, a LaTeX table is created. But all tables have the same line:

\label{table:coefficients}

LaTeX complains that this same label was included multiple times, thus not allowing you to reference any specific table.

To remedy the situation, you can include the label argument in your texreg calls as in the following example:

texreg(mymodel, label = "firsttable")

Make sure you change the label for each table.

0
Foad S. Farimani On

A perl-bash snippet has been developed here:

perl -nE "say $1 if /(\\label[^}]*})/" *.tex | sort | uniq -c 

which searches the .tex file for all \label{...}s using the regular expression \\label[^}]*} and then sot-group them by the number of occurance. Just fix the labels with more than 1 occurance (duplicated ones) and the warning should go away.

0
JensE On

Just add perl -lne 'print unless /^\s*1/' at the end of perl -nE "say $1 if /(\\label[^}]*})/" *.tex | sort | uniq -c, so you get just the multi-defined labels.

perl -nE "say $1 if /(\\label[^}]*})/" *.tex | sort | uniq -c | perl -lne 'print unless /^\s*1/'