超链接到 flextable 中的每一行

hyperlinks to each row in flextable

我有一个数据框

df = data.frame("A" = c("a","b","c","d"), "B" = c(1,2,3,4), "link" = c("www.a.com", "www.b.com", "www.c.com", "www.d.com"))

A B link

a 1 www.a.com

b 2 www.b.com

c 3 www.c.com

d 4 www.d.com

我的格式是table

dt.ft <- regulartable(data = dt[, list(A, B, link)])

我想让 "A" 列中的值与 "link" 列中的相应值超链接。

我试过了

compose(x = dt.ft, j = "A", value = as_paragraph( hyperlink_text(x = A, url = link)))

我收到以下错误:

Error in $<-.data.frame(*tmp*, "url", value = c(1L, 2L, 3L, 4L, 1L, : replacement has 16 rows, data has 4

如果 table 中只有 1 行,则上述 R 语句有效,但对多行无效。你能帮我么。 另外,在链接后,有什么方法可以 hide/remove 列 "link"。

首先,有一个问题,0.5.2版本应该会修复。

library(flextable)

df = data.frame("A" = c("a","b","c","d"), "B" = c(1,2,3,4), "link" = c("www.a.com", "www.b.com", "www.c.com", "www.d.com"))
dt.ft <- flextable(data = df, col_keys = c("A", "B"))
dt.ft <- compose(x = dt.ft, j = 1, value = as_paragraph( hyperlink_text(x = A, url = link)))
dt.ft

该示例还显示了如何使用参数 col_keys.

select 您希望显示的列