【发布时间】:2021-12-28 17:19:00
【问题描述】:
我正在使用 R 包 DT 创建一个表。此表包含超链接,我遇到的问题是,当我输入 rownames = FALSE 以删除行号时,超链接上的格式消失了。我想知道是否有人解决了这个问题?
示例数据:
structure(list(school = structure(c(2L, 3L, 1L, 4L), .Label = c("Linfield",
"OSU", "UO", "Willamette"), class = "factor"), mascot = structure(c(2L,
3L, 4L, 1L), .Label = c("bearcats", "beavers", "ducks", "wildcats"
), class = "factor"), website = structure(c(1L, 3L, 2L, 4L), .Label = c("<a href=\"http://oregonstate.edu/\">oregonstate.edu</a>",
"<a href=\"https://www.linfield.edu/\">linfield.edu</a>", "<a href=\"https://www.uoregon.edu/\">uoregon.edu</a>",
"<a href=\"https://www.willamette.edu/\">willamette.edu</a>"), class = "factor"),
School_colors = structure(c(2L, 1L, 3L, 4L), .Label = c("<span style=\"color:green\">green & yellow</span>",
"<span style=\"color:orange\">orange & black</span>", "<span style=\"color:purple\">purple and red</span>",
"<span style=\"color:red\">red and yellow</span>"), class = "factor")), class = "data.frame", row.names = c(NA,
-4L))
用于生成带有行名的表的代码
datatable(df,escape = c(1,2,3))
用于生成没有行名的表的代码
datatable(df, rownames = FALSE,escape = c(1,2,3))
如您所见,在第二个示例代码中,第三列中的格式不再存在。我想要做的是创建一个没有行号的表格,但也要保持超链接的格式
【问题讨论】: