“Formal argument ”foo“ matched by multiple arguments” - how to deal with this in R?

前端 未结 2 967
清酒与你
清酒与你 2021-02-07 11:37

Sometimes, calling a function with certain arguments results in the error message formal argument \"foo\" matched by multiple actual arguments. Is it possible to pr

2条回答
  •  故里飘歌
    2021-02-07 11:41

    library(mixtools)
    wait = faithful$waiting
    mixmdl = normalmixEM(wait)
    
    plot(mixmdl, which = 2, xlim = c(25, 110), ylim = c(0, .5), nclass=20)
    #Error in hist.default(x, prob = TRUE, main = main2, xlab = xlab2, ylim = c(0,  : 
    #  formal argument "ylim" matched by multiple actual arguments
    

    The error message is quite informative. It tells you which function gets passed the parameter twice. For more information:

    traceback()
    
    # 4: hist.default(x, prob = TRUE, main = main2, xlab = xlab2, ylim = c(0, 
    #                                                                      maxy), ...)
    # 3: hist(x, prob = TRUE, main = main2, xlab = xlab2, ylim = c(0, 
    #                                                              maxy), ...)
    # 2: plot.mixEM(mixmdl, which = 2, xlim = c(25, 110), ylim = c(0, 
    #                                                              0.5), nclass = 20)
    # 1: plot(mixmdl, which = 2, xlim = c(25, 110), ylim = c(0, 0.5), 
    #         nclass = 20)
    

    So, there is a call to hist in plot.mixEM that already sets ylim = c(0,maxy). Your ylim = c(0,0.5) gets passed via the ellipsis (...), so that hist.default gets passed ylim twice. Hence, the error.

提交回复
热议问题