编织为html时,数据框中的值会变形。值小于3个字符时会发生,如下所示。-5770正确转换为,(5770)
但-577结果577.
后面附加了li元素。这是knitr的错误还是我的代码中的错误?
round_numeric <- function(num, prec = 0) {
return (round(as.numeric(num), prec))
}
format_numeric <- function(num, prec = 0) {
rounded_num <- abs(round_numeric(num, prec))
res <- format(rounded_num, nsmall = prec, big.mark = ',', trim = TRUE)
return (ifelse(num >= 0, res, sprintf('(%s)', res)))
}
col1 <- format_numeric(-5770)
col2 <- format_numeric(-577)
col3 <- format_numeric(300)
df <- t(data.frame(row1 = c(col1, col2, col3)))
df %>%
kable(align = 'c', format = 'html') %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
在R-studio中正确输出:
使用R-studio将Knit转换为html时,html文件中的输出错误:
因此,问题是(577)
括号中的in或任何整数被pandocs列为有序列表。为了防止这种情况,您可以在YAML中禁用它,只需添加以下内容即可。
output:
html_document:
md_extensions: "-fancy_lists"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句