gpt4 book ai didi

r - 如何在 Sweave 文档的表格中包含超链接?

转载 作者:行者123 更新时间:2023-12-04 11:02:02 25 4
gpt4 key购买 nike

我有一个包含超链接的数据框,我想使用 Sweave 将其显示为可点击的链接。 .我知道 xtable ,但不确定如何使用它来将数据框的内容视为 LaTeX 命令。

最佳答案

一种策略是使用 sanitize.text.function来自 print函数在 xtable .
设置 sanitize.text.function = function(x){x}原因 print只是为了回显数据帧的内容以供 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}

...产生这个PDF输出:
enter image description here

关于r - 如何在 Sweave 文档的表格中包含超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24132503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com