【问题标题】:Export Pivot table R in Markdown pdf format以 Markdown pdf 格式导出数据透视表 R
【发布时间】:2021-07-15 18:52:36
【问题描述】:

我想获得一些关于将数据透视表导出为 pdf 文件的提示。 我已经按照http://www.pivottabler.org.uk/ 此处描述的方法进行了操作,但是出现了一条错误消息。 它指的是pdfcrop和ghostscript。

我在论坛上发了很多消息(包括Got knit issue with R)并尝试重新安装Markdown,tinytex没有结果。 由于我没有安装 pdfcrop 和 ghostscrip 的管理员权限,我想寻求帮助以获得替代解决方案.... (Rstudio v1.3) 由于我在复杂数据表,理想情况下我想继续使用打包器,它可以避免我重新开始

谢谢

---
title: "Untitled"
output: pdf_document
header-includes:
  -\usepackage{multirow}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r results='asis', echo=FALSE, comment=""}
pt <- PivotTable$new()
pt$addData(bhmTrains)
pt$addColumnDataGroups("TrainCategory") 
pt$addRowDataGroups("TOC",  header="Spécialité",  addTotal=FALSE)
pt$defineCalculation(calculationName="TOTAL", 
                                 summariseExpression="n()")
cat(pt$getLatex(caption="test", label="xxxxx"))
```

我收到以下消息

Error in pt$getLatex : objet de type 'closure' non indiçable
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> cat
De plus : Warning message:
In has_crop_tools() :
Tool(s) not installed or not in PATH: pdfcrop, ghostscript
-> As a result, figure cropping will be disabled.

【问题讨论】:

    标签: r r-markdown markdown pivot-table


    【解决方案1】:

    现在是考虑使用 Rmarkdown 的 DT 包的好时机。这是带有html_document 输出的代码,这使您能够在用户制作自己的数据透视表后将数据表直接从文档打印到 PDF!

    ---
    title: "Untitled"
    output: html_document
    ---
    
    
    ### Chart 1
    ```{r echo = FALSE, message=FALSE, warning=FALSE}
    
    
    library(DT)
    library(tidyverse)
    
    
    iris %>%
      datatable(extensions = 'Buttons',
                options = list(dom = 'Blfrtip',
                               buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                               lengthMenu = list(c(10,25,50,-1),
                                                 c(10,25,50,"All"))))
    ```
    

    但对于 PDF 输出,您只需修改输出参数即可。

    ---
    title: "Untitled"
    output: pdf_document
    ---
    
    
    ### Chart 1
    ```{r echo = FALSE, message=FALSE, warning=FALSE}
    
    
    library(DT)
    library(tidyverse)
    
    
    iris %>%
      datatable(extensions = 'Buttons',
                options = list(dom = 'Blfrtip',
                               buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                               lengthMenu = list(c(10,25,50,-1),
                                                 c(10,25,50,"All"))))
    ```
    

    我喜欢 DT 包,因为它允许您按列排列并将新排列保存为它自己的表,这就是数据透视表。 DT也有更多的可能性。

    【讨论】:

    • 感谢丹尼尔的建议。由于我需要自动化表格和报告,我查看了 DT 的功能来做交叉表、组和子摘要,最后我选择了看起来最合适的 GT 包。因此,我可以轻松地在 PNG 中导出表格并将它们导入 markdown(带有 pdf 输出)。
    猜你喜欢
    • 2017-10-15
    • 1970-01-01
    • 2021-07-11
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    相关资源
    最近更新 更多