更新到 R 4.3.0(在 macOS 13.3.1 上)后,在编译 Markdown 文档时收到一条错误消息:
Error: package or namespace load failed for 'kableExtra':
.onLoad failed in loadNamespace() for 'kableExtra', details:
call:!is.null(rmarkdown::metadata$output)&&rmarkdown::metadata$output%in%
error: 'length = 3' in coercion to 'logical(1)'
Execution halted
Run Code Online (Sandbox Code Playgroud)
在 R Studio 中运行各个块不会出现错误消息。
我已经重新安装了 kableExtra 和所有依赖项。
我正在尝试制作一个使用渲染的rmarkdown文档render()
.该render
调用有两个参数化元素:
output_format()
.kableExtra
包)是否为latex或html.这是名为test.Rmd的rmarkdown文件
---
title: "Title"
author: "Zzz Zzzzzz"
params:
table_format:
value
---
```{r setup}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)
options(knitr.table.format = params$table_format)
```
## Test table
```{r cars}
if (params$table_format == "latex"){
kable(iris[1:100,], booktabs = T) %>%
kable_styling(latex_options = c("scale_down"))
}
if (params$table_format == "html"){
kable(iris[1:100,]) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>%
scroll_box(width = "500px", height = "600px")
}
params$table_format
```
Run Code Online (Sandbox Code Playgroud)
现在这里有两个渲染文件的调用:
rmarkdown::render("test.Rmd", output_format = "pdf_document", params = list( …
Run Code Online (Sandbox Code Playgroud) 我试图在R中的特定列周围创建边框.我能够使用kableExtra包(如下所示)
iris <- datasets::iris
iris2 <- do.call(data.frame, aggregate(. ~ Species, iris, function(x) c(mean = mean(x), sd = sd(x))))
res2 <- kable(iris2,"html", col.names = c("Species", "Mean", "SD", "Mean", "SD", "Mean", "SD", "Mean", "SD"), align = c("r","c","c","c","c","c","c","c","c")) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>%
add_header_above(c(" " = 1, "Sepal Length" = 2, "Sepal Width" = 2, "Petal Length" = 2, "Petal Width" = 2))
print(res2)
res3<- column_spec(res2, c(2,4,6,8), border_left = TRUE, border_right = FALSE)
column_spec(res3, c(3,5,7,9), border_left = FALSE, border_right = …
Run Code Online (Sandbox Code Playgroud) 我想用rmarkdown创建一个pdf.PDF应包含一个表格.该表应具有动态列标签.
标签应显示日历周.
但是,不显示日历周(例如,KW29),而是显示变量名称"kw0".
我的错误是什么?
library(knitr)
library(kableExtra)
library(lubridate)
options(knitr.table.format = "latex")
loadData <- function() {# load some data}
myData<- loadData ()
kw0 <- paste("KW", week(Sys.Date()) - 1, sep = "")
kw1 <- paste("KW", week(Sys.Date()), sep = "")
kw2 <- paste("KW", week(Sys.Date()) + 1, sep = "")
kw3 <- paste("KW", week(Sys.Date()) + 2, sep = "")
kable(myData, row.names = FALSE, booktabs = T) %>%
kable_styling(
full_width = TRUE,
font_size = 14
) %>% add_header_above(header = c(" " = 1, kw0 = 2, …
Run Code Online (Sandbox Code Playgroud) 我是新来的,但我在 R 上花了几个小时。我正在使用 R 包 Drake 与 knitr 的组合。\n但是我的 Rmarkdown 文件有错误。我有一个与德雷克示例类似的结构( https://github.com/ropensci/drake)类似的结构,我在其中加载数据,制作图表,然后绘制统计分析的图表和汇总表(使用 R 包 kableextra) 。
\n当我选择 .tex 文件时,一切正常,我的 Rmarkdown 文件上有以下几行
\n output: latex_document\n\n tables: true\n graphics: yes \n
Run Code Online (Sandbox Code Playgroud)\n和德雷克计划
\nreport = rmarkdown::render(\nknitr_in("Reports/report.Rmd"),\noutput_file = "report.tex")\n
Run Code Online (Sandbox Code Playgroud)\n但是当我想要一个已编译的 pdf 文件作为输出,其中 rmarkdown 标头包含以下几行:
\noutput:\n pdf_document: \n latex_engine: xelatex\n\ntables: true\ngraphics: yes\n
Run Code Online (Sandbox Code Playgroud)\n和德雷克
\nreport = rmarkdown::render(\nknitr_in("Reports/report.Rmd"),\noutput_format = "pdf_document",\noutput_file = "report.pdf")\n
Run Code Online (Sandbox Code Playgroud)\n我收到一条错误消息:
\n`! Undefined control sequence.\n<template> ...\\hskip 1sp\\d@llarbegin \\columncolor \n [HTML]{BBBBBB}\\ignorespaces \nl.178 \\em{Predictors} & \\em\n {Coefficients} …
Run Code Online (Sandbox Code Playgroud) 我使用以下模板
---
title: "Nice try buddy"
author: "SpaceMan"
date: "13 December 2057"
output:
bookdown::pdf_document2
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage[table]{xcolor}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
---
---
references:
- id: fenner2012a
title: One-click science marketing
container-title: Nature Materials
volume: 11
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Title
\begin{equation}
f\left(k\right)=\binom{n}{k}p^k\left(1-p\right)^{n-k} \label{eq:binom}
\end{equation}
You may refer to it using `\@ref(eq:binom)`, e.g., …
Run Code Online (Sandbox Code Playgroud) 我使用深色 RStudio 主题并尝试knitrExtra
在 R Markdown 文档中打印表格。不幸的是,表格的主要内容是不可见的(即白色背景上的白色符号)。
问题:如何使用kableExtra
深色 RStudio 编辑器主题使 R Markdown 文档中的表格内容可见?
代码示例:
```{r}
library(kableExtra)
head(iris) %>%
knitr::kable(caption = "**Table 1.** Iris data. ", digits = 2) %>%
kableExtra::kable_styling()
```
Run Code Online (Sandbox Code Playgroud)
输出示例:
如果选择文本,内容会暂时可见,但这不是我正在寻找的解决方案:
RStudio 版本: 1.1.463
kabeExtra
版本: 0.9.0
我需要能够减少或简化此表中的数字。我只希望显示最多 4 个小数位,如果可能的话,如果数字是整数,则只显示整数。我将如何做到这一点?
library(kableExtra)
x = c(1, 1, 1, 1, 1, 1, 1, 1, 1)
y = x/2
z = x/3
a = data.frame(x, y, z)
b = t(a)
c = kable(b, "html", align = "c") %>%
kable_styling(full_width = F)
Run Code Online (Sandbox Code Playgroud) 是否可以设置字幕格式kableExtra
?我想在编织时将表格的标题居中并HTML
加粗RMarkdown
。我尝试将表格包装在CSS div
文本居中的位置,但这没有产生预期的结果。
样本表:
library(kableExtra)
kable(data.frame(a = 1:3, b = 4:6), caption = "CENTER") %>%
kable_styling(bootstrap_options = "striped")
Run Code Online (Sandbox Code Playgroud)
产量:
我想:
嗨我用这个很棒的桌子kableExtra
,但我唯一的问题是行的高度并不总是相等.有没有人知道这方面的补救措施?
我的桌子:
例如,如您所见,项目编号22(第6行)的行具有比其他行更大的高度(间距).
我的代码:
my_column_names = c("Item number", "Item",
"Emotion", "Social",
"At Home", "Body", "Emotion",
"Social 1", "Social 2",
"At Home", "Body")
kable(df1,
format = "latex", booktabs = TRUE,
col.names = my_column_names,
caption = "Factor loadings for the 4 and 5 Factor Model") %>%
kable_styling(latex_options = c("striped", "hold_position"),
full_width = FALSE) %>%
add_header_above(c(" " = 2,
"4 Factor Model " = 4, "5 Factor model" = 5)) %>%
add_header_above(c(" " = 2,
"Model" = 9)) %>%
kableExtra::landscape()
Run Code Online (Sandbox Code Playgroud)