Question

I am using knitr and rstudio to write a report. I am attempting to print the results to a factor analysis using the fa2latex() function in the psych package. I am wanting to reference the resulting table in the text of my report. The fa2latex function prints a latex label command, however I have not seen a way to edit the latex command. I know I could edit the label after the tex file has been created, but I would like to do it in my rnw file. Does anyone know how to change the default label command in the latex output that results from the fa2latex function in the psych package.

Here is some code to use as an example.

library(psych)
data(Thurstone)
fa.Thurstone<-fa(Thurstone)
fa2latex(fa.Thurstone)

The results are this:

% fa2latex % fa.Thurstone 
\begin{tiny} \begin{table}[htdp]\caption{fa2latex}
\begin{center}
\begin{tabular} {l r r r }
 \multicolumn{ 3 }{l}{ A factor analysis table from R } \cr 
 \hline Variable  &   MR1  &  MR1.1  &  MR1.2 \cr 
  \hline 
Sentences   &  0.87  &  0.75  &  0.25 \cr 
 Vocabulary   &  0.88  &  0.77  &  0.23 \cr 
 Sent.Completion   &  0.83  &  0.70  &  0.30 \cr 
 First.Letters   &  0.62  &  0.39  &  0.61 \cr 
 4.Letter.Words   &  0.61  &  0.37  &  0.63 \cr 
 Suffixes   &  0.59  &  0.34  &  0.66 \cr 
 Letter.Series   &  0.57  &  0.32  &  0.68 \cr 
 Pedigrees   &  0.64  &  0.41  &  0.59 \cr 
 Letter.Group   &  0.52  &  0.27  &  0.73 \cr 
\hline \cr SS loadings & 4.32 &  \cr \hline 
\end{tabular}
\end{center}
\label{default}
\end{table} 
\end{tiny}

What I am wondering is if there is a way to change the default in the \label{default} command.

I have tried

fa2latex(fa.Thurstone, label="newlabel")

but this tells me

    Error in fa2latex(fa.Thurstone, label = "newlabel") : 
  unused argument (label = "newlabel")

Does anyone know a way to change this?

Was it helpful?

Solution

The short answer is no, but it is an easy patch. Change line 1 to include "label"

"fa2latex" <- 
function(f,digits=2,rowlabels=TRUE,apa=TRUE,short.names=FALSE,font.size ="tiny", heading="A factor analysis table from R",caption="fa2latex",label="default") {

and then change the lines defining footer to

footer <- paste(footer,"
\\end{tabular}
\\end{center}
\\label{",label,"}
\\end{table} 
\\end{",font.size,"}
",sep=""
)

I will include this correction in the next release.

Bill

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top