Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:58:13+00:00 2026-06-03T19:58:13+00:00

I’m using the ‘caret’ library to to do some cross validation on some trees.

  • 0

I’m using the ‘caret’ library to to do some cross validation on some trees.

The library provides a function called train, that takes in a named argument “method”. Via its ellipsis it’s supposed to let other arguments fall through to another function that it calls. This other function (rpart) takes an argument of the same name, “method”.

Therefore I want to pass two arguments with the same name… and it’s clearly failing. I tried to work around things as shown below but I get the error:

“Error in train.default(x = myx, y = myy, method = “rpart2”, preProcess = NULL, :
formal argument “method” matched by multiple actual arguments”

any help is much appreciated! thanks!

train.wrapper = function(myx, myy, mytrControl, mytuneLenght, ...){
   result = train(
                        x=myx,
                        y=myy,
                        method="rpart2",
                        preProcess=NULL,
                        ...,
                        weights=NULL,
                        metric="Accuracy",
                        trControl=mytrControl,
                        tuneLength=mytuneLenght

                      )
   return (result)
 }
dtree.train.cv = train.wrapper(training.matrix[,2:1777], 
                               training.matrix[,1], 
                               2, method="class")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:58:16+00:00Added an answer on June 3, 2026 at 7:58 pm

    Here’s a mock-up of your problem with a tr (train) function that calls an rp (rpart) function, passing it ...:

    rp <- function(method, ...) method
    tr <- function(method, ...) rp(...)
    
    # we want to pass 2 to rp:
    tr(method=1, method=2) # Error
    tr(1, method=2)        # 1, (wrong value!)
    tr(method=1, metho=2)  # 2 (Yay!)
    

    What magic is this? And why does the last case actually work?! Well, we need to understand how argument matching works in R. A function f <- function(foo, bar) is said to have formal parameters “foo” and “bar”, and the call f(foo=3, ba=13) is said to have (actual) arguments “foo” and “ba”.

    R first matches all arguments that have exactly the same name as a formal parameter. This is why the first “method” argument gets passed to train. Two identical argument names cause an error.

    Then, R matches any argument names that partially matches a (yet unmatched) formal parameter. But if two argument names partially match the same formal parameter, that also causes an error. Also, it only matches formal parameters before .... So formal parameters after ... must be specified using their full names.

    Then the unnamed arguments are matched in positional order to the remaining formal arguments.

    Finally, if the formal arguments include ..., the remaining arguments are put into the ....

    PHEW! So in this case, the call to tr fully matches method, and then pass the rest into .... When tr then calls rp, the metho argument partially matches its formal parameter method, and all is well!

    …Still, I’d try to contact the author of train and point out this problem so he can fix it properly! Since “rpart” and “rpart2” are supposed to be supported, he must have missed this use case!

    I think he should rename his method parameter to method. or similar (anything longer than “method”). This will still be backward compatible, but allows another method parameter to be passed correctly to rpart.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.