当编织到html时,dataframe中的值会被扭曲。当值小于3个字符时会发生这种情况,如下所示。-5770被正确地转换为(5770),但是-577在577.后加上安莉元素。这是一个带有针织品的错误还是我的代码中的错误?
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中的正确输出:

在使用针织到html的html文件中使用R-studio输出错误:

发布于 2021-02-18 07:45:50
所以问题是,(577)或括号中的任何整数都会被混乱的词组定义为有序列表。要防止这种情况,您可以在YAML中禁用此功能,只需添加以下内容即可。
output:
html_document:
md_extensions: "-fancy_lists"https://stackoverflow.com/questions/66255413
复制相似问题