转义下划线 (\\_) 没有正确转义
Escape underscore (\\_) not escaping correctly
我正在使用带 github_document 的 kableExtra,但我的下划线输出不正确。
在我尝试转义它之前,table 是这样输出的:
然后我尝试看看是否可以通过转义下划线来摆脱反斜杠,但没有成功。
我试图用 \_
\_
和 \\_
来逃避所有这些都没有给我想要的结果。使用:
\_
R 表示它不是有效的转义命令
\_
在我的 table 中打印 \_
\\_
在我的 table. 中打印 \\_
我的 YAML:
---
output: github_document
always_allow_html: true
---
块选项:
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
示例代码:
names_table <- data.frame(name = c("Heat Index", "Heat Index Extreme Caution", "Heat Index Dangerous", "Temperature over the 95th percentile"), df_name = c("heat\_index", "heat\_index\_ec", "heat\_index\_dan", "temp\_over\_95\_pctl"), calculation = c("Heat index calculation", "Temperature between 90-102F", "Temperature between 103-124F", "Temperature exceeds historic 95th pctl"))
names_table %>%
knitr::kable(col.names = c("Variable Name",
"Column Name",
"Variable Calculation"),
escape = TRUE,
format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
full_width = F,
position = "center") %>%
column_spec(3, width = "20em")
如果我 运行 代码 没有 kable_styling
,它 运行s 正确(即输出是我想要的)但是如果我 knit 文档,我的 table 仍然打印不需要的反斜杠。
我搜索了 SO 但没有找到任何帮助,但也许我在某处误解了一些帮助。
编辑:添加了问题图片,添加了有关问题产生原因的更多信息。
通过将 table 另存为图像并将 table 作为图像插入到我的 markdown 中,我找到了解决问题的方法。没有解决 github_document
的输出在下划线前添加反斜杠的问题。从上面继续:
kable_out <- names_table %>%
knitr::kable(col.names = c("Variable Name",
"Column Name",
"Variable Calculation"),
escape = TRUE,
format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
full_width = F,
position = "center") %>%
column_spec(3, width = "20em")
save_kable(kable_out, "man/figures/kable_table.png", zoom = 5)
# zoom preserves image quality
knitr::include_graphics("man/figures/kable_table.png")
我正在使用带 github_document 的 kableExtra,但我的下划线输出不正确。
在我尝试转义它之前,table 是这样输出的:
然后我尝试看看是否可以通过转义下划线来摆脱反斜杠,但没有成功。
我试图用 \_
\_
和 \\_
来逃避所有这些都没有给我想要的结果。使用:
\_
R 表示它不是有效的转义命令\_
在我的 table 中打印 \\_
在我的 table. 中打印
\_
\\_
我的 YAML:
---
output: github_document
always_allow_html: true
---
块选项:
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
示例代码:
names_table <- data.frame(name = c("Heat Index", "Heat Index Extreme Caution", "Heat Index Dangerous", "Temperature over the 95th percentile"), df_name = c("heat\_index", "heat\_index\_ec", "heat\_index\_dan", "temp\_over\_95\_pctl"), calculation = c("Heat index calculation", "Temperature between 90-102F", "Temperature between 103-124F", "Temperature exceeds historic 95th pctl"))
names_table %>%
knitr::kable(col.names = c("Variable Name",
"Column Name",
"Variable Calculation"),
escape = TRUE,
format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
full_width = F,
position = "center") %>%
column_spec(3, width = "20em")
如果我 运行 代码 没有 kable_styling
,它 运行s 正确(即输出是我想要的)但是如果我 knit 文档,我的 table 仍然打印不需要的反斜杠。
我搜索了 SO 但没有找到任何帮助,但也许我在某处误解了一些帮助。
编辑:添加了问题图片,添加了有关问题产生原因的更多信息。
通过将 table 另存为图像并将 table 作为图像插入到我的 markdown 中,我找到了解决问题的方法。没有解决 github_document
的输出在下划线前添加反斜杠的问题。从上面继续:
kable_out <- names_table %>%
knitr::kable(col.names = c("Variable Name",
"Column Name",
"Variable Calculation"),
escape = TRUE,
format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
full_width = F,
position = "center") %>%
column_spec(3, width = "20em")
save_kable(kable_out, "man/figures/kable_table.png", zoom = 5)
# zoom preserves image quality
knitr::include_graphics("man/figures/kable_table.png")