Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

r - Who do i properly display a vtable in RMarkdown?

since I am a newbee in RMarkdown and/or R in general, I am having a bit of trouble with the following:

I would like to display a vtable (created using the library vtable) as a normal kable table in RMarkdown (I am creating a PDF with LaTex). I understand that vtable can give back a knitr kable and therefore it can be used as an input for kable_styling so i can tinker with the latex options. This seems to work up to a certain point.

Here is the code so far:

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

But the resulting table looks like this: enter image description here

Why are the latex command displayed at all?

I am thankful of any help you can give me.

The database can be found here: https://archive.ics.uci.edu/ml/datasets/Heart+failure+clinical+records

And here ist the complete Rmd File:


    ---
    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
    ```
    
ewpage  
    # 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"))
    ```

Greetings!

Edit: code formatting

question from:https://stackoverflow.com/questions/65861159/who-do-i-properly-display-a-vtable-in-rmarkdown

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...