自动命名 table 并导出为图像?

Automate naming of table and export as image?

我有这个自动脚本可以生成 table 并且按年份显示“thetarget”标记的频率:

library(quanteda)

vec <- c("Apple", "Google")    

out <- map(vec, ~ 
         df %>%
  filter(str_detect(collectionName, .x)) %>%
  filter(str_detect(Year, paste(years, collapse = "|"))) %>%
  corpus(text_field = "text") %>%
  tokens() %>%
  tokens_select(thetarget) %>%
  dfm() %>%
  dfm_group(groups = "Year") %>%
  convert(to = "data.frame")
)

names(out) <- sub("^(...).*\s+(\S)$", "\1\2", vec)

正在使用

 View(out$Apple)

产生对应的table.

我正在尝试自动将这些 table 导出为 pdf 或 jpeg,例如文件名为“Apple”。

有办法吗?

TIA

我无法执行您的代码块(函数 convert 有问题,它来自哪个库?)- 但这不是问题。

存在很多解决方案,但是,f.e。,您可以使用包 gtflextable 来完成此任务(一堆输出类型)。

首先,安装webshotPhantomJS。 在安装其他软件包后 (gt 和 flextable)。查看示例:

(gt)

tab_1 <-
    gtcars %>%
    dplyr::select(model, year, hp, trq) %>%
    dplyr::slice(1:5) %>%
    gt(rowname_col = "model") %>%
    tab_stubhead(label = "car") %>%
    gtsave("tab_1.png", expand = 10, path = "********")

(可弯曲)

   ft <- flextable(head(mtcars))
   save_as_image(x = ft, path = "********\image_name.png")