gpt4 book ai didi

r - 取消R的胶水包中的新行预防

转载 作者:行者123 更新时间:2023-12-05 07:30:30 24 4
gpt4 key购买 nike

在 glue 包中,您“可以在行尾使用\\来防止添加换行符”。在 LaTeX 中,\\是换行符。

我正在寻找比我目前的解决方案更好的解决方案

glue_data(iris,
"\\midrule
\\textbf{{{mean(Petal.Length)}} & 820 & 100\\% \\\\
~other & 902 \\\\"
)

实际输出:

\midrule
\textbf{3.758} & 820 & 100\% \~other & 902 \\

预期输出:

\midrule
\textbf{3.758} & 820 & 100\% \\
~other & 902 \\

我目前丑陋且容易出错的修复:

glue_data(iris,
"\\midrule
\\textbf{{{mean(iris$Petal.Length)}} & 820 & 100\\% \\\\\\
\n~other & 902 \\\\"
)

\midrule
\textbf{3.758} & 820 & 100\% \\
~other & 902 \\

最佳答案

我发现一个更好的方法是将 LaTeX 换行符添加为变量以防止它们被 glue 解释:

lineb <- '\\\\'
glue_data(
iris,
"\\midrule
\\textbf{{{mean(Petal.Length)}} & 820 & 100\\% {lineb}
~other & 902 \\\\"
)

输出

\midrule
\textbf{3.758} & 820 & 100\% \\
~other & 902 \\

关于r - 取消R的胶水包中的新行预防,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52225367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com