kableExtra在[R]中突然崩溃 [英] Sudden collapse of kableExtra in [R]

查看:107
本文介绍了kableExtra在[R]中突然崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能应该指出,我对使用RMarkdownkableExtra R软件包仍然很陌生,但是我有一个上周可以编织的文档,尽管对该文档没有任何物理更改,但现在不再可以编织. .我收到的错误消息如下

I should probably point out that I am still fairly new to working with RMarkdown and the kableExtra R package, but I have a document that was knitable last week and now no longer knits despite no physical changes to the document. The error message I receive is the following

save_kable_latex(x,file,latex_header_includes,keep_tex)中的错误:尝试使用magick读取生成的PDF文件时遇到错误.您可以检查magick安装并尝试使用magick :: image_read手动读取PDF文件.也有可能您没有安装ghostscript.调用...-> as_image-> save_kable-> save_kable_latex停止执行

通过重新安装magick R软件包,安装ghostscript(通过Homebrew)等,我尝试了所有可以想到的事情.

I have tried everything that I can think of by re-installing the magick R package, installing ghostscript (through Homebrew), etc.

下面给出的代码块似乎就是问题所在,其中tab2是一个数据帧,其某些元素是LaTeX表达式,例如"\\sum_x f(x)*\\left ( pe(x) - lcl(x) \\right )".

And the code chunk given below seems to be where the issues are occurring, where tab2 is a data frame with some of its elements being a LaTeX expressions such as "\\sum_x f(x)*\\left ( pe(x) - lcl(x) \\right )".

kable( tab2, format="latex", escape=FALSE, align="c", col.names=NULL ) %>%
  kable_styling( latex_options=c('hold_position') ) %>%
  footnote( general="Given x successes out of n trials, the holistic Jeffreys $100*(1-\\\\alpha)\\\\%$ Lower $\\\\textit{Credible}$ Limit is the value $p$ such that $\\\\int_0^p \\\\frac{t^{x+0.5-1}(1-t)^{n-x+0.5-1}}{B(x+0.5,n-x+0.5)} dt = \\\\alpha$ where B(a,b) is the Beta function given by $\\\\int_0^1 t^{(x-1)}(1-t)^{(y-1)} dt$.",
           general_title="", threeparttable = TRUE,
            footnote_as_chunk=TRUE, escape=FALSE ) %>%
  as_image( file="tab2.png", width=8, units="in" )

,然后在新幻灯片上使用include_graphics()功能将其打印为PDF.

and printed to the PDF later on using the include_graphics() function on a new slide.

任何帮助将不胜感激,因为这是工作演示.

Any assistance would be greatly appreciated as this is for a work presentation.

编辑#1

根据要求,这是一个最低工作示例

As requested, here is a Minimum Working Example

prob.success <- sample( seq(.5,.99,.01), size=1 )
conf.alpha <- sample( seq(.5,.99,.01), size=1 )

tab1 <- data.frame( x=0:5, f=round(dbinom(0:5,5,prob.success),3) ) %>%
  mutate( pe=x/5, lcl=qbeta(1-conf.alpha,x+0.5,5-0:5+0.5) ) %>%
  mutate( lcl=pmin(pe,lcl) ) %>%
  mutate( delta=pe-lcl ) %>%
  mutate( f_delta=f*delta )

exp.expr <- "\\sum_x f(x)*\\left ( pe(x) - lcl(x) \\right )"
exp.delta <- format( round(sum( tab1$f_delta ),4), nsmall=4 )

tab2 <- tab1 %>%
  mutate( x=as.character(x), f=format(round(f,4),nsmall=4) ) %>%
  mutate( pe=format(round(pe,4),nsmall=4) ) %>%
  mutate( lcl=format(round(lcl,4),nsmall=4) ) %>%
  mutate( delta=format(round(delta,4),nsmall=3) ) %>%
  mutate( f_delta=format(round(f_delta,4),nsmall=4) ) %>%
  rbind( ., data.frame(x="",f="",pe="",lcl="",delta="",f_delta="") ) %>%
  rbind( ., data.frame(x="", f="", pe="Exp", lcl="Diff", delta="=", f_delta=exp.expr) ) %>%
  rbind( ., data.frame(x="",f="",pe="",lcl="",delta="=",f_delta=exp.delta) ) %>%
  rbind( data.frame(x="x",f="f(x)",pe="pe(x)",lcl="lcl(x)",delta="pe(x)-lcl(x)",
                    f_delta="f(x)\\times\\left(pe(x)-lcl(x)\\right)"), . )

编辑#2

这些是.Rmd文件中使用的R包

And these are the R packages used in the .Rmd file

library( knitr )
library( tibble )
library( magrittr )
library( dplyr )
library( kableExtra )
library( stringr )
library( magick )

推荐答案

在与kableExtra作者Hao Zhu进行多封电子邮件后,建议使用HTML表(而不是LaTeX).结果,以下代码能够成功呈现.非常感谢郝.

After several emails with the kableExtra author Hao Zhu, it was suggested that a HTML table (instead of LaTeX) should be used. As a result, the following code was able to render successfully. Many thanks to Hao.

对原始帖子的更改包括

exp.expr <- "$\\sum_x f(x)*\\left ( pe(x) - lcl(x) \\right )$"

tab2 <- tab1 %>%
  mutate( x=as.character(x), f=format(round(f,4),nsmall=4) ) %>%
  mutate( pe=format(round(pe,4),nsmall=4) ) %>%
  mutate( lcl=format(round(lcl,4),nsmall=4) ) %>%
  mutate( delta=format(round(delta,4),nsmall=3) ) %>%
  mutate( f_delta=format(round(f_delta,4),nsmall=4) ) %>%
#  rbind( ., data.frame(x="",f="",pe="",lcl="",delta="",f_delta="") ) %>%
  rbind( ., data.frame(x="", f="", pe="Exp", lcl="Diff", delta="=", f_delta=exp.expr) ) %>%
  rbind( ., data.frame(x="",f="",pe="",lcl="",delta="=",f_delta=exp.delta) ) # %>%
#  rbind( data.frame(x="x",f="f(x)",pe="pe(x)",lcl="lcl(x)",delta="pe(x)-lcl(x)",
#                    f_delta="f(x)\\times\\left(pe(x)-lcl(x)\\right)"), . )

tab.cols <- c( "x", "f(x)", "pe(x)", "lcl(x)", "pe(x)-lcl(x)",
                "$f(x)\\times\\left(pe(x)-lcl(x)\\right)$" )

kable( tab2, format="html", escape=FALSE, align="c", col.names=tab.cols ) %>%
  kable_styling( "striped", full_width = F, position="center" ) %>%
  footnote( general="Given x successes out of n trials, the holistic Jeffreys $100*(1-\\alpha)\\%$ Lower *Credible* Limit is the value $p$ such that $\\int_0^p \\frac{t^{x+0.5-1}(1-t)^{n-x+0.5-1}}{B(x+0.5,n-x+0.5)} dt = \\alpha$ where B(a,b) is the Beta function given by $\\int_0^1 t^{(x-1)}(1-t)^{(y-1)} dt$.",
           general_title="Note:", footnote_as_chunk=TRUE, escape=FALSE )

这篇关于kableExtra在[R]中突然崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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