2014-06-10 17 views

Odpowiedz

5

Jedną z nich jest użycie funkcji sanitize.text.function z funkcji print w xtable. Ustawianie sanitize.text.function = function(x){x} przyczyn print prostu echo zawartość ramki danych do późniejszej interpretacji przez LaTeX:

\documentclass{article} 

\usepackage{hyperref} 

\begin{document} 
\title{Example of how to include hyperlinks in Sweave with \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, 
    now with added hyperlinks." 
    ), 
    include.rownames=FALSE, 
    sanitize.text.function = function(x){x} 
) 

@ 

\end{document} 

... która produkuje ten wyjściowe PDF: enter image description here

Powiązane problemy