如何将 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 (将#修改为@)