在使用 knitr 时,我在让 C++ 代码(通过内联包中的 cxx 函数编写)显示得很好时遇到了问题。这是一个 MWE:

<html>
<body>

<!--begin.rcode
library(Rcpp)
library(inline)
test <- cxxfunction(signature(xR="numeric"), body="
  double x = as<double>(xR);
  return(wrap(x));
  ", plugin="RcppArmadillo")
end.rcode-->

</body>
</html>

当我编写这段代码时,它通过用“\n”替换所有新行来重新格式化 body 参数,这使得它很难阅读。是否有任何解决方法?

最佳答案

release notes of knitr 1.6 中列出了一个重大更改:默认块选项 tidy = TRUE 已更改为 FALSE 。这就是为什么您的换行符不再使用 knitr 1.6 变成文字 \n

关于r - inline::cxxfunction 在 knitr 中显示不佳,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24312108/

10-11 23:06
查看更多