首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >粘贴在绘图表达式中是一个特殊的参数吗?

粘贴在绘图表达式中是一个特殊的参数吗?
EN

Stack Overflow用户
提问于 2013-10-24 10:11:46
回答 1查看 828关注 0票数 9

当向一个情节标题提供一个plotmath表达式时,我认为paste的工作方式与paste一样,但现在我不确定。它是plotmath函数的一个特殊参数吗?在绘图中,paste()的行为类似于paste0()paste0,而paste()sep参数则被忽略,但在表达式中没有引用。如何解释paste()?见以下四个例子:

代码语言:javascript
复制
#  Data to plot
x <- seq( 55 , 70 , length = 2001 )
probs <- dexp( x , rate = 5 / 60  )
s <- sample( x , 10000 , prob = probs , repl = TRUE )


#  Some plots
par(mfrow = c(2,2) )
#1)  paste() behaves like paste0() here
hist( s , breaks = 30 , 
    main = expression( paste( "1: Sampling of" , Phi , "Distribution" ) ) ,
    xlab = "No spaces in title using paste()" , axes = F )

#2)  add spaces in the expression where they are needed
hist( s , breaks = 30 , 
    main = expression( paste( "2: Sampling of "  , Phi , " Distribution" ) ) ,
    xlab = "Single spaces in titles: paste() behaves like paste0()" , axes = F )

#3)  Don't put spaces, use a sep argument - ignored
hist( s , breaks = 30 , 
    main = expression( paste( "3: Sampling of"  , Phi , "Distribution" , sep = " " ) ) ,
    xlab = "No spaces using paste(), `sep` argument is ignored but not quoted in expression" , axes = F )

#4)  paste0 is not recognised
hist( s , breaks = 30 , 
    main = expression( paste0( "4: Sampling of " , Phi , " Distribution" ) ) ,
    xlab = "paste0() not recognised" , axes = F )

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-24 14:52:10

的确,paste在计谋中并不是经典的paste。请参阅?plotmath

粘贴( x,y,z)并列x,y,z

pasteplotmath上下文中没有sep参数。

在源代码plotmath.c中,您可以看到重新定义了paste

代码语言:javascript
复制
/*----------------------------------------------------------------------
*
* Code for Concatenate Expressions
*
*/

static int ConcatenateAtom(SEXP expr)
{
    return NameAtom(expr) && NameMatch(expr, "paste");
}

static BBOX RenderConcatenate(SEXP expr, int draw, mathContext *mc,
                         pGEcontext gc, pGEDevDesc dd)
{
    BBOX bbox = NullBBox();
    int i, n;

    expr = CDR(expr);
    n = length(expr);

    for (i = 0; i < n; i++) {
        bbox = CombineBBoxes(bbox, RenderElement(CAR(expr), draw, mc, gc, dd));
        if (i != n - 1)
         bbox = RenderItalicCorr(bbox, draw, mc, gc, dd);
        expr = CDR(expr);
    }
    return bbox;
}

它稍后在文件中被发送:

代码语言:javascript
复制
static BBOX RenderFormula(SEXP expr, int draw, mathContext *mc,
                         pGEcontext gc, pGEDevDesc dd)
{
    SEXP head = CAR(expr);

    ....
    else if (ConcatenateAtom(head))
        return RenderConcatenate(expr, draw, mc, gc, dd);
    ....

(话虽如此,我对C一无所知,所以我在那件事上可能错了)

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19563042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档