【问题标题】:DataExplorer Cannot Create PDF ReportDataExplorer 无法创建 PDF 报告
【发布时间】:2021-06-03 00:49:19
【问题描述】:

我正在尝试使用 R DataExplorer 包生成一些报告,但由于某种原因,虽然 html 报告的工作原理很吸引人,但 pdf 报告的创建却惨遭失败。 这可能是一个 pandoc 问题,但请查看帖子末尾的 reprex。

欢迎提出任何建议!

library(DataExplorer)

create_report(iris
             ,
              output_file = "report.html") ### this works
#> processing file: report.rmd
#> output file: /tmp/RtmpnWllz3/reprex347124a8c7df/report.knit.md
#> /usr/bin/pandoc +RTS -K512m -RTS /tmp/RtmpnWllz3/reprex347124a8c7df/report.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output /tmp/RtmpnWllz3/reprex347124a8c7df/report.html --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --standalone --section-divs --table-of-contents --toc-depth 6 --template /usr/local/lib/R/site-library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:yeti' --include-in-header /tmp/RtmpDWU78N/rmarkdown-str348854cbcbb6.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
#> 
#> Output created: report.html


## but this does not!


create_report(iris
             ,
              output_file = "report.pdf") 
#> processing file: report.rmd
#> output file: /tmp/RtmpnWllz3/reprex347124a8c7df/report.knit.md
#> /usr/bin/pandoc +RTS -K512m -RTS /tmp/RtmpnWllz3/reprex347124a8c7df/report.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output /tmp/RtmpnWllz3/reprex347124a8c7df/report.pdf --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --standalone --section-divs --table-of-contents --toc-depth 6 --template /usr/local/lib/R/site-library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:yeti' --include-in-header /tmp/RtmpDWU78N/rmarkdown-str348863c0475e.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
#> Error: pandoc document conversion failed with error 1

## how to fix it....


print(sessionInfo())
#> R version 4.0.4 (2021-02-15)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux 10 (buster)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] knitr_1.31         rmarkdown_2.6      data.table_1.13.6  DataExplorer_0.8.2
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.6        plyr_1.8.6        pillar_1.4.7      compiler_4.0.4   
#>  [5] highr_0.8         tools_4.0.4       digest_0.6.27     jsonlite_1.7.2   
#>  [9] evaluate_0.14     lifecycle_1.0.0   tibble_3.0.6      gtable_0.3.0     
#> [13] pkgconfig_2.0.3   rlang_0.4.10      reprex_1.0.0      igraph_1.2.6     
#> [17] DBI_1.1.1         curl_4.3          parallel_4.0.4    yaml_2.2.1       
#> [21] xfun_0.21         gridExtra_2.3     xml2_1.3.2        httr_1.4.2       
#> [25] styler_1.3.2      stringr_1.4.0     dplyr_1.0.4       generics_0.1.0   
#> [29] fs_1.5.0          vctrs_0.3.6       htmlwidgets_1.5.3 grid_4.0.4       
#> [33] tidyselect_1.1.0  glue_1.4.2        R6_2.5.0          reshape2_1.4.4   
#> [37] farver_2.0.3      ggplot2_3.3.3     purrr_0.3.4       magrittr_2.0.1   
#> [41] backports_1.2.1   scales_1.1.1      ellipsis_0.3.1    htmltools_0.5.1.1
#> [45] networkD3_0.4     assertthat_0.2.1  mime_0.10         colorspace_2.0-0 
#> [49] labeling_0.4.2    stringi_1.5.3     munsell_0.5.0     crayon_1.4.1

由reprex package (v1.0.0) 于 2021-03-04 创建

【问题讨论】:

    标签: r pdf pandoc


    【解决方案1】:

    我认为这是DataExplorer::create_report() 中的一个错误,因为它使用了一个自定义的 R Markdown 模板,其中有一些函数可以生成 HTML 格式的输出。这会在以 PDF 格式生成输出时导致错误。我在作者的GitHub上提出了一个更正,如果更正被接受我会更新这个答案。

    但是,您的代码中也有一些需要更改的地方。您需要致电:

    create_report(iris, output_file = "report.pdf", output_format = "pdf_document") 
    

    而不是:

    create_report(iris, output_file = "report.pdf") 
    

    同时可以编辑DataExplorer提供的Rmd模板:

    • 找到文件:system.file("rmd_template/report.Rmd", package = "DataExplorer")

    • 打开它,然后在 YAML 中添加 always_allow_html: true(就在 title: 部分之后)

    运行 create_report(iris, output_file = "report.pdf", output_format = "pdf_document") 现在应该可以工作了。但是请注意,如果您更新软件包,此更正将会消失。

    【讨论】:

    • 谢谢。很高兴知道至少有一个潜在的解决方案正在筹备中。
    • @larry77 你已经可以在本地更正包了,我添加了一个关于如何做的简要说明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 2014-10-05
    • 2016-01-30
    • 2013-01-18
    相关资源
    最近更新 更多