R - Conditional row highlighting in HTML table created using xtable or kable

后端 未结 4 1154
天命终不由人
天命终不由人 2020-12-30 05:55

I\'m pretty much a beginner at programmatically formatting R output, but I\'ve got a basic understanding of knitr, xtable, Markdown, and Pandoc\'s

4条回答
  •  没有蜡笔的小新
    2020-12-30 06:15

    I've played around a good amount with formatting RMarkdown documents.

    Since RMarkdown gets converted to LaTeX before the end PDF is generated, you can pass arguments that would work in LaTeX to RMarkdown. So, adding

    header-includes:
      - \usepackage{xcolor}
    

    in the heading of the RMarkdown document, and then adding something like

    for(i in seq(1, nrow(yourDataframe), by = 2)){
      yourDataframe[i, ] <- paste0("\\color{purple}", yourDataframe[i, ])
      row.names(yourDataframe)[i] <- paste0("\\color{purple}", row.names(yourDataframe)[i])
    }
    

    will get you purple (or whatever color specified and allowed in the xcolor LaTeX package) entries in every other row of your table. Just another way to emphasize entries that isn't the base bold or italics given.

    This isn't row highlighting, but could give you further customizable options.

    *Tested with the pander package.

    **You'll need to convert any factor columns to character columns for this method.

提交回复
热议问题