0

嗨,我在下面的 .rmd 文档中有这个示例数据框,我想将其显示为带有kableExtra包的表格。问题是我不能用第一列的“链接名”替换第二列的 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)

```
4

1 回答 1

1

如果我正确理解了您的问题,则您正在尝试使用一列“名称”链接到列出的站点,但仅显示“链接名称”而不是完整的 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)
于 2018-01-30T00:57:12.830 回答