如何在 officer 中命名列“”以前在 ReporteRs 中可以做到

How to name a column " " in officer was able to do it previously in ReporteRs

这对我来说是个大问题,因为我需要在 officer 的 flextable 中有未命名的列名。这以前适用于 ReporteRs 版本。 但到目前为止还没有能够做到这一点,尝试使用以下代码:

rename(` ` = col0)

当我 运行 尝试使用此列名称创建一个 flextable 时,我收到以下错误消息: flextable(a) 中的错误: 无效col_keys,flextable 仅支持句法名称

data <- head(iris) %>%
  rename(` ` = Sepal.Length)
myft <- regulartable(data)
myft1<- flextable(data)

注意:regulartable(data) 有效,列名为空。 当尝试使用 flextable 执行此操作时,它不起作用并且出现错误

我能用 flextable 做到这一点吗?

非常感谢

您无需修改​​ data.frame 即可自定义显示。拥有像 </code> 这样的名字是有风险的 IHMO。阅读 <a href="https://davidgohel.github.io/flextable/articles/layout.html#manage-headers-and-footers" rel="nofollow noreferrer">https://davidgohel.github.io/flextable/articles/layout.html#manage-headers-and-footers</a></p> <pre><code>library(flextable) library(magrittr) library(dplyr) data <- head(iris) myft <- regulartable(data) %>% set_header_labels(Sepal.Length = " ") myft1 <- flextable(data) %>% set_header_labels(Sepal.Length = " ") myft1