0

Hi i have this example dataframe in the .rmd document below which i want to display as a table with the kableExtra package. The problem is that i cannot replace the urls of the second column with the "linkname" of the first and still keep them working as hyperlinks in a pdf document.

---
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)

```
firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

1

If I am understanding your question correctly, you are trying to have one column "name" that links to the listed sites but only displays the "linkname" as opposed to the full url.

Try the below.

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)
Greg B
  • 86
  • 4
  • Im afraid that it does not work with this option knitr::kable(df,format = "latex") – firmo23 Jan 30 '18 at 03:28
  • i do not think you need to include the format option. You have already declared your rmd to output pdf. format will be automatically determined if the function is called within knitr. when you "knit" your rmd to pdf output it should produce the desired format automatically. – Greg B Jan 30 '18 at 16:47
  • ok there was another issue irrelevant with this which i fixed so i can accept your answer.Tnx – firmo23 Jan 30 '18 at 17:27