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 8438027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:35:42+00:00 2026-06-10T07:35:42+00:00

I have created a function which has a reasonably large number of parameters (all

  • 0

I have created a function which has a reasonably large number of parameters (all vectors of the same length) and I thought it would make life easier to be able to bundle up the parameters in a data frame. I have managed to achieve this using S3 methods, but reading a bit more about S3 methods, I am starting to wonder whether the way I have coded my functions is a bit of an abuse of S3 conventions.

I’d like to know whether what I have done is a bad idea or not. If it is, alternative approaches would be welcome.

Here is a simplified example of what I have done:

myfunc <- function(x, ...) UseMethod("myfunc")

myfunc.default(time, money, age, weight) {
   # a silly calculation
   return(money/(age + weight) - time)
}

myfunc.data.frame <- function(params, ...) {
  names(params) <- tolower(names(params))
  pass.args <- intersect(names(params), names(formals(myfunc.default)))
  res <- do.call(myfunc.default, c(params[pass.args], ...))
  return(res)
}

Then if I had a data frame mydata with column names Money, time, AGE, weight and name then a call like this myfunc(mydata) would pass the relevant data to myfunc.default. It all works well, but is it wise?

  • 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-10T07:35:43+00:00Added an answer on June 10, 2026 at 7:35 am

    Thanks for the comments. I have concluded my strategy of using S3 methods here was a bad idea. I have switched to two functions, such as myfunc and myfunc_df. I have also created a helper function for doing the heavy lifting of turning a function with individual arguments into one which accepts a data frame:

    df_call <- function(.function, .parameters, .case=tolower, ...) {
      try(names(.parameters) <- match.fun(.case)(names(.parameters)))
      pass.args <- intersect(names(.parameters), names(formals(.function)))
      do.call(.function, c(.parameters[pass.args], list(...)))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an utility function which I include in almost all Javascript code
Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have created a add input field function which is working fine. I would
Imagine you have a function tree which has a number of nodes which can
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I have created a JS function which executes fine when it's included an the
i have function, which has to accept two types of data - Observable collection
I have created a class say A which has some functions defined as protected.
I have created an applet which has a necessity to execute the following code:
I have a class which can't be created on heap and it has private

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.