如何用 kableExtra 创建的 table 中的单词替换超链接并将其显示在 pdf 文档中

How to replace a hyperlink with a word in table created with kableExtra and display it in a pdf document

您好,我在下面的 .rmd 文档中有这个示例数据框,我想将其显示为带有 kableExtra 包的 table。问题是我无法用第一列的 "linkname" 替换第二列的 url,并且仍然让它们作为 pdf 文档中的超链接工作。

---
title: "Clinical Table"
author: EK
date: January 29, 2018
output: 
  pdf_document: 
  keep_tex: yes
---

```{r nice-tab, tidy=FALSE,echo=FALSE,message=FALSE} 
library(dplyr)
library(kableExtra)
library(rmarkdown)
library(knitr)
  df<-data.frame(rep("linkname",10))
df$url<- c("https://en.wikipedia.org/wiki/Cadillac_Fleetwood",
           "https://www.lincoln.com/luxury-cars/continental/",
           "http://shop.honda.com/civics.aspx",
           "https://bringatrailer.com/2011/12/28/striking-1973-maserati-bora-4-9/",
           "https://en.wikipedia.org/wiki/Cadillac_Fleetwood",
           "https://www.lincoln.com/luxury-cars/continental/",
           "http://shop.honda.com/civics.aspx",
           "https://bringatrailer.com/2011/12/28/striking-1973-maserati-bora-4-9/",
           "https://en.wikipedia.org/wiki/Cadillac_Fleetwood",
           "https://www.lincoln.com/luxury-cars/continental/")
names(df)[1]<-"name"

df$name<- paste("<a href=\"",df$url,"\">",df$name,"</a>",sep="")


kable(
  df, caption = 'REPORT TABLE',
  booktabs = TRUE,format = "latex",escape = FALSE
)%>%
kable_styling(full_width = T)

```

如果我没有正确理解你的问题,你试图让一列 "name" 链接到列出的网站,但只显示 "linkname" 而不是完整的 url .

试试下面的方法。

df<-data.frame(name = rep("linkname",10))
url<- c("https://en.wikipedia.org/wiki/Cadillac_Fleetwood",
       "https://www.lincoln.com/luxury-cars/continental/",
       "http://shop.honda.com/civics.aspx",
       "https://bringatrailer.com/2011/12/28/striking-1973-maserati-bora-4-9/",
       "https://en.wikipedia.org/wiki/Cadillac_Fleetwood",
       "https://www.lincoln.com/luxury-cars/continental/",
       "http://shop.honda.com/civics.aspx",
       "https://bringatrailer.com/2011/12/28/striking-1973-maserati-bora-4-9/",
       "https://en.wikipedia.org/wiki/Cadillac_Fleetwood",
       "https://www.lincoln.com/luxury-cars/continental/")

df$name <- paste0("[", df$name, "](", url, ")")

knitr::kable(df)