r - How can I include hyperlinks in a table within an Sweave document? -
i have data frame containing hyperlinks present clickable links using sweave
. know xtable
, not sure how use treat contents of data frame latex commands.
one strategy use sanitize.text.function
print
function in xtable
. setting sanitize.text.function = function(x){x}
causes print
echo contents of data frame later interpretation latex:
\documentclass{article} \usepackage{hyperref} \begin{document} \title{example of how include hyperlinks in sweave \texttt{xtable}} \author{david r. lovell} \maketitle <<load-packages, include=false>>= require(xtable) @ <<read-data, tidy=false>>= hits <- read.table(textconnection( "count,link,title 1031,http://australianbioinformatics.net/jobs,jobs 796,http://australianbioinformatics.net/,home"), stringsasfactors=false, sep=",", header=true) @ <<print-xtable, echo = false, results = 'asis'>>= print( xtable( hits, align="rrll", caption="top content on \\href{http://australianbioinformatics.net}{australianbioinformatics.net} in may 2014." ), include.rownames=false ) @ <<print-xtable-href, echo = false, results = 'asis'>>= linkedhits <- transform(hits, href=paste("\\href{", link, "}{", title, "}", sep="")) print( xtable( subset(linkedhits, select=c(count, href)), align="rrl", caption="top content on \\href{http://australianbioinformatics.net}{australianbioinformatics.net} in may 2014, added hyperlinks." ), include.rownames=false, sanitize.text.function = function(x){x} ) @ \end{document}
...which produces pdf output:
Comments
Post a Comment