【问题标题】:Who do i properly display a vtable in RMarkdown?我应该在 RMarkdown 中正确显示谁的 vtable?
【发布时间】:2021-04-27 20:45:19
【问题描述】:

由于我是 RMarkdown 和/或 R 的新手,我在以下方面遇到了一些麻烦:

我想在 RMarkdown 中将 vtable(使用库 vtable 创建)显示为普通的 kable 表(我正在使用 LaTex 创建 PDF)。我知道 vtable 可以返回一个 knitr kable,因此它可以用作 kable_styling 的输入,所以我可以修改乳胶选项。这似乎在一定程度上起作用。

这是目前为止的代码:

vtable(heart_faliure_data, labels = label) %>% 
kable_styling(latex_options = c("striped", "scale_down"))

但结果表如下所示:

为什么要显示latex命令?

感谢您能给我的任何帮助。

数据库可以在这里找到:https://archive.ics.uci.edu/ml/datasets/Heart+failure+clinical+records

这里是完整的 Rmd 文件:


    ---
    title             : "Data mining using R for heart failure clinical records Dataset"
    
    floatsintext      : yes
    figurelist        : yes
    tablelist         : yes
    footnotelist      : no
    linenumbers       : no
    linkcolor         : "blue"
    mask              : no
    draft             : no
    
    classoption       : "doc"
    output            : papaja::apa6_pdf
documents
    header-includes:
    - \usepackage{booktabs}
    - \usepackage{longtable}
    - \usepackage{array}
    - \usepackage{multirow}
    - \usepackage{wrapfig}
    - \usepackage{float}
    - \usepackage{colortbl}
    - \usepackage{pdflscape}
    - \usepackage{tabu}
    - \usepackage{threeparttable}
    - \usepackage{threeparttablex}
    - \usepackage[normalem]{ulem}
    - \usepackage{makecell}
    - \usepackage{xcolor}
    ---
    
    ```{r include = FALSE}
    library("tidyverse")
    library("kableExtra")
    library("rsample")
    library("recipes")
    library("parsnip")
    library("yardstick")
    library("viridisLite")
    library("GGally")
    library("vtable")
    library("qwraps2")
    library("ggplot2")
    library("htmlTable")
    library("egg")
    library("dplyr")
    library("afex")
    library("papaja")
    library("kableExtra")
    library("magrittr")
    library("vtable")
    
    knitr::opts_chunk$set(echo = TRUE)
    heart_faliure_data <- read.csv(file = "../Data/heart_failure_clinical_records_dataset.csv", header = FALSE, skip=1)
    c_names <- c("Age",
                 "Anaemia",
                 "cr_ph",
                 "diabetes",
                 "ejection_fraction",
                 "high_blood_pressure",
                 "platelets",
                 "serum_creatinine",
                 "serum_sodium",
                 "sex",
                 "smoking",
                 "time",
                 "DEATH_EVENT")
    colnames(heart_faliure_data) <- c_names
    ```
    \newpage  
    # Introductiom
    
    ```{r echo=FALSE}
    knitr::kable(head(heart_faliure_data), booktabs = TRUE) %>%
              kable_styling(latex_options = c("striped", "scale_down"))
    ```
    
    ```{r echo=FALSE}
    label <- data.frame(
      Age = "Age of the patient",
      Anaemia = "Decrease of red blood cells or hemoglobin",
      creatinine_phosphokinase = "level of the CPK enzyme in the blood (mcg/L)",
      diabetes = "if the patient has diabetes",
      ejection_fraction = "percentage of blood leaving the heart at each contraction",
      high_blood_pressure = "if the patient has hypertension",
      platelets = "platelets in the blood (kiloplatelets/mL)",
      serum_creatinine = "level of serum creatinine in the blood (mg/dL)",
      serum_sodium = "level of serum sodium in the blood (mEq/L)",
      sex = "sex of the patient, woman or man",
      smoking = "if the patient smokes or not",
      time = "follow-up period",
      DEATH_EVENT = " if the patient deceased during the follow-up period"
    )
    
    vtable(head(heart_faliure_data), labels = label, out="latex") #%>%
              kable_styling(latex_options = c("striped", "scale_down"))
    ```

您好!

编辑:代码格式

【问题讨论】:

标签: r latex r-markdown vtable kableextra


【解决方案1】:

代码中的out = 'latex' 是问题所在。 out = 'latex' 生成 LaTeX 代码作为输出,而不是 kable,覆盖您通过在 RMarkdown 文档中运行 vtable 获得的默认 kable 输出。您可以通过删除 out = 'latex' 选项或将其更改为 out = 'kable' 来解决此问题。

抱歉没有尽快回复,我可能应该为 vtable 设置警报或其他设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多