Rmarkdown和kable_save()中的kableExtra HTML样式 [英] kableExtra HTML styling in Rmarkdown and kable_save()

查看:153
本文介绍了Rmarkdown和kable_save()中的kableExtra HTML样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这困扰了我太久了,我将不胜感激.我一直在花时间在电缆上,但是它对我来说还不是我想要的那样.我正在寻找创建图像中的多组行

执行此操作的代码如下:

  collapse_rows_dt<-expand.grid(District = sprintf('District%s',c('1','2')),City = sprintf('City%s',c('1','2')),State = sprintf('State%s',c('a','b')),Country = sprintf('长名称国家/地区%s', c('A', 'B')))crash_rows_dt<-crash_rows_dt [c(国家",州",城市",区")]crash_rows_dt $ C1 = rnorm(nrow(collapse_rows_dt))crash_rows_dt $ C2 = rnorm(nrow(collapse_rows_dt))kbl(collapse_rows_dt,booktabs = T,align ="c",linesep ='')%>%crash_rows(1:3,row_group_label_position ='stack') 

问题是,当我在R markdown中运行它时,我在输出中获得HTML版本(请参见下文)

这显然不够好.如果我将其编织为pdf,则可以得到正确的输出(第一张图像),仅此而已.如果我尝试执行save_kable(),结果将显示为HTML格式,如第二幅图像所示.每次都编织成pdf格式是不切实际的,如果无法解决此问题,我将无法再使用kable.对我来说这很重要.

如果我设置format ='latex',则内联中什么也没有显示,当我尝试kable_save()时,我收到以下错误消息:

这是Xtex版本3 ....(tex live 2020/w32Tex)预加载格式= xlatex)受限制的\ write18启用.进入扩展模式

后面有一个通知我的弹出窗口(R崩溃)

R 会话中止,r遇到致命错误

所有不需要乳胶的HTML表格都会以适当的方式内联显示,并保存为实际图像.

相关的最新软件包:

 -库(网络快照)库(tinytex)(也尝试不使用)图书馆(魔术)图书馆(plyr)图书馆(tidyverse)图书馆(dplyr)图书馆(针织)图书馆(skimr)图书馆(kableExtra) 

也:

  • Ghostscript 9.52是当前版本,并已设置为环境
  • Miktext 2.9

尝试过:

  • 通过install.packages(magick

    • 在ImageMagick中编辑policy.xls以绕过安全功能

      This has plagued me for too long, I would appreciate help. I have been investing time into kable, but it hasn't quite worked out for me the way I would like. I am looking to create multi grouped rows as in the image

      The code to do this is as follows:

      collapse_rows_dt <- expand.grid( District = sprintf('District %s', c('1', '2')), City = sprintf('City %s', c('1', '2')), State = sprintf('State %s', c('a', 'b')), Country = sprintf('Country with a long name %s', c('A', 'B'))
      )
      collapse_rows_dt <- collapse_rows_dt[c("Country", "State", "City", "District")] 
      collapse_rows_dt$C1 = rnorm(nrow(collapse_rows_dt)) 
      collapse_rows_dt$C2 = rnorm(nrow(collapse_rows_dt))
      
      kbl(collapse_rows_dt, booktabs = T, align = "c", linesep = '') %>%
      collapse_rows(1:3, row_group_label_position = 'stack')
      

      The problem is that when I run this in R markdown I get the HTML version in the output (see below)

      This obviously is not good enough. I CAN get the correct output (first image) if I knit to pdf, but that's it. If I try doing save_kable() it turns out in the HTML format as in the second image. Kniting to pdf every time is so impractical that I can't possible use kable anymore if I can't fix this. That is a big deal for me.

      If I set format='latex' then nothing shows up inline and when I try to kable_save() I get this error message:

      this is Xtex version 3....(tex live 2020/w32Tex) preloaded format=xlatex) restricted \write18 enabled. Entering extended mode

      Followed by a pop that informs me (R crashes)

      R session aborted, r encoutered a fatal error

      All HTML tables that don't require latex show up inline appropriately and will save as their actual image.

      Relevant Up to Date Packages:

      -     library(webshot) 
            library(tinytex) (also tried without)
            library(magick) 
            library(plyr) 
            library(tidyverse) 
            library(dplyr)
            library(knitr) 
            library(skimr) 
            library(kableExtra)
      

      Also:

      • Ghostscript 9.52 is current and set to environment
      • Miktext 2.9

      Have Tried:

      • updating imageMagick via install.packages(magick

      • Manually installing the following Latex packages

        • library(tinytex)tlmgr_install(pkgs = 'standalone')tlmgr_install(pkgs = 'preview')tlmgr_install(pkgs = 'polyglossia')tlmgr_install(pkgs = 'xltxtra')tlmgr_install(pkgs = 'realscripts')
      • Setting Mixtex to environment path

      解决方案

      If you want to knit and include the image produced via LaTeX and PDF, you can use kableExtra::as_image

      ---
      output: html_document
      ---
      
      ```{r}
      library(kableExtra)
      library(magrittr)
      
      collapse_rows_dt <- expand.grid( District = sprintf('District %s', c('1', '2')), City = sprintf('City %s', c('1', '2')), State = sprintf('State %s', c('a', 'b')), Country = sprintf('Country with a long name %s', c('A', 'B'))
      )
      
      collapse_rows_dt <- collapse_rows_dt[c("Country", "State", "City", "District")] 
      collapse_rows_dt$C1 = rnorm(nrow(collapse_rows_dt)) 
      collapse_rows_dt$C2 = rnorm(nrow(collapse_rows_dt))
      
      kbl(collapse_rows_dt, "latex", align="c", linesep="", booktabs = T) %>%
        collapse_rows(1:3, row_group_label_position = 'stack') %>%
        kable_styling(latex_options = c("striped", "scale_down")) %>%
        as_image()
      ```
      

      这篇关于Rmarkdown和kable_save()中的kableExtra HTML样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆