微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将 R Sweave 中用户定义函数的文本输出包装为 pdf

如何解决如何将 R Sweave 中用户定义函数的文本输出包装为 pdf

当通过 Sweave 编译为 pdf 时,我们无法让用户定义函数输出换行文本,而是跑出页面并且不可读。下面给出了类似于用户定义函数之一的输出示例代码

我们正在 Sweave 中寻找一种解决方案,我们可以在其中调用函数并将输出包装在 pdf 的边距内。如果可能,我们希望避免编辑函数本身。

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<>>=
long_output <- function(x,group){
  var1 <- paste0(group,"_",x,".devcmn")
  var2 <- paste0(group,".cmn")
  resNames <- c(var1,var2)
  class(resNames) <- "long_output"
  return(resNames)
}

print.long_output <- function(x){
  cat("The following variables (group summary,deviation) were added to the dataset:",x[1],x[2],'\n')
  cat("See package documentation for detailed description of variables added.")
}

long_output("Variable","Grouping")
@

\end{document}

我们尝试了以下页面上的解决方案,但没有成功:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。