[Tex/LaTex] Creating a PDF output using Latex and R-Markdown… keep getting an error

codepdftexrstudio

I have a file I'm working on in R-Studio, and it was working really well (have about two pages worth of output that does work). But when I try to add to it with a new table, I keep getting:

> "Running pdflatex.exe on playerArbitrationProfile.tex...failed"

The problem is in the R-code that prints the table. Here's what I currently have for that:

<<echo=False,results=tex>>=   
print(xtable((transactions),align=c(rep('c',3),rep('c',ncol(transactions)-2))),sanitize.colnames.function=bold,include.rownames=FALSE,latex.environments = "left",hline=NULL,floating=FALSE, size="\\fontsize{2pt}{3pt}\\selectfont",add.to.row=list(pos=list(1:(nrow(transactions)),0), command=c( '\\midrule\n','\\toprule\n')),tabular.environment = 'tabularx', width="7in")
@

The table (built in R) has three columns: transaction date (character), transaction team (character), and transaction description (character). The table has 17 observations. The transaction description column is slightly lengthy, but I don't think the length is the issue considering I tried running it without that column and it didn't make a difference (on another note, if anyone can give an easy way to get the text to wrap in that third column, that would be appreciated). Does anyone see any issues in the code above that would keep preventing my report from running?

Thanks!

Best Answer

I think the problem might be you are using Sweave (results=tex) syntax, but using knitr (where the syntax would be results='asis')

In any case, the following compiles for me

\documentclass[landscape]{article}
\usepackage{tabularx}
\usepackage{booktabs}

<<data, echo=FALSE>>=
    transactions <- as.data.frame( list(
        date       = paste("date" , 1:17) ,
        team       = paste("team" , 1:17),
        decription = paste('description' , 1:17)
    ) )
@

<<setup, echo=FALSE>>=
    library(xtable)

    bold <- function(x) {
        paste0('\\textbf{' , x , '}')
    }
@

\begin{document}

<<table, echo=FALSE , results='asis'>>=   
    print(
        xtable(transactions,align=c(rep('c',3),rep('c',ncol(transactions)-2))) ,
        sanitize.colnames.function = bold,
        include.rownames=FALSE,
        latex.environments = "left",
        hline=NULL,
        floating=FALSE,
        size="\\fontsize{2pt}{3pt}\\selectfont",
        add.to.row=list(pos=list(1:(nrow(transactions)),0), command=c( '\\midrule\n','\\toprule\n')),
        tabular.environment = 'tabularx',
        width="7in"
    )
@

\end{document}

EDIT: Working Sweave version:

\documentclass[landscape]{article}
\usepackage{tabularx}
\usepackage{booktabs}

<<data, echo=FALSE>>=
    transactions <- as.data.frame( list(
        date       = paste("date" , 1:17) ,
        team       = paste("team" , 1:17),
        decription = paste('description' , 1:17)
    ) )
@

<<setup, echo=FALSE>>=
    library(xtable)

    bold <- function(x) {
        paste0('\\textbf{' , x , '}')
    }
@

\begin{document}
\SweaveOpts{concordance=TRUE}

<<table, echo=FALSE , results=tex>>=   
    print(
        xtable(transactions,align=c(rep('c',3),rep('c',ncol(transactions)-2))) ,
        sanitize.colnames.function = bold,
        include.rownames=FALSE,
        latex.environments = "left",
        hline=NULL,
        floating=FALSE,
        size="\\fontsize{2pt}{3pt}\\selectfont",
        add.to.row=list(pos=list(1:(nrow(transactions)),0), command=c( '\\midrule\n','\\toprule\n')),
        tabular.environment = 'tabularx',
        width="7in"
    )
@

\end{document}