【问题标题】:Remove brackets in Sweave output删除 Sweave 输出中的括号
【发布时间】:2015-11-07 00:46:22
【问题描述】:

我想知道是否有办法直接在文本中打印 R 对象(Sweave),但直接在一行文本中。

我想打印这段代码

\documentclass{article}

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

YO MANNNNNNN 2+2 = 
<<here, results=tex, echo=FALSE>>=
2+2
@
YEAHHHH!

\end{document}

我想要一个类似这样的输出:

YO MANNNNNNN 2+2 = 4 YEAHHHH! 

但是,R 正在像这样添加答案括号

YO MANNNNNNN 2+2 = [1] 4YEAHHHH! 

【问题讨论】:

    标签: r sweave


    【解决方案1】:

    代码:

    \documentclass{article}
    
    \begin{document}
    % \SweaveOpts{concordance=TRUE}
    
    YO MANNNNNNN 2+2 = \Sexpr{2+2} YEAHHHH! 
    
    \end{document}
    

    n.b.对我来说,注释掉 \SweaveOpts{concordance=TRUE} 工作得很好,但您需要根据您的设置取消注释。

    打印:

    YO MANNNNNNN 2+2 = 4 YEAHHHH!
    

    更新 - 每条评论的额外信息...

    您可以在“块”中定义一个对象,以便稍后使用 \Sexpr{} 在线评估

    <<somechunk, results='tex',echo=FALSE, results='hide'>>=
    x <- 2
    @
    
    Inline evaluation of x prints the number \Sexpr{x}.
    

    【讨论】:

    • 很好,非常感谢。它对我来说完美无缺。也可以放置这样的对象objecthere=2+2 YO MANNNNNNN 2+2 = \Sexpr{objecthere} YEAHHHH!
    猜你喜欢
    • 2023-01-15
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 2018-02-25
    相关资源
    最近更新 更多