问题描述
由于我是 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"))
```
您好!
编辑:代码格式
解决方法
代码中的 out = 'latex'
是问题所在。 out = 'latex'
生成 LaTeX 代码作为输出,而不是 kable
,覆盖通过在 RMarkdown 文档中运行 vtable
获得的默认 kable 输出。您可以通过删除 out = 'latex'
选项或将其更改为 out = 'kable'
来解决此问题。
很抱歉没有尽快回复,我可能应该为 vtable 设置一个警报或其他内容。