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:
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
```
\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"))
```
Greetings!
Edit: code formatting