要么不重新格式化代码(使用chunk 选项 tidy=FALSE)并手动缩进两个空格,
<<tidy=FALSE>>=
if (TRUE) {
# code here
}
@
Run Code Online (Sandbox Code Playgroud)
或者将 R 选项设置reindent.spaces为较小的值,例如
options(reindent.spaces = 2)
Run Code Online (Sandbox Code Playgroud)
此选项被传递到formatR包以重新缩进您的代码,并且knit默认情况下使用formatR重新格式化您的 R 代码。