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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:09:45+00:00 2026-05-29T19:09:45+00:00

Does R support function overloading ?? I want to do something in the lines

  • 0

Does R support function overloading ??

I want to do something in the lines of :

g <- function(X,Y) { # do something and return something } 
g <- function(X) { # do something and return something} 
  • 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-05-29T19:09:46+00:00Added an answer on May 29, 2026 at 7:09 pm

    EDIT, following clarification of the question in comments above:

    From a quick glance at this page, it looks like Erlang allows you to define functions that will dispatch completely different methods depending on the arity of their argument list (up to a ..., following which the arguments are optional/don’t affect the dispatched method).

    To do something like that in R, you’ll probably want to use S4 classes and methods. In the S3 system, the method that is dispatched depends solely on the class of the first argument. In the S4 system, the method that’s called can depend on the classes of an arbitrary number of arguments.

    For one example of what’s possible, try running the following. It requires you to have installed both the raster package and the sp package. Between them, they provide a large number of functions for plotting both raster and vector spatial data, and both of them use the S4 system to perform method dispatch. Each of the lines returned by the call to showMethods() corresponds to a separate function, which will be dispatched when plot() is passed x and y arguments that having the indicated classes (which can include being entirely "missing").

    > library(raster)
    > showMethods("plot")
    Function: plot (package graphics)
    x="ANY", y="ANY"
    x="Extent", y="ANY"
    x="Raster", y="Raster"
    x="RasterLayer", y="missing"
    x="RasterStackBrick", y="ANY"
    x="Spatial", y="missing"
    x="SpatialGrid", y="missing"
    x="SpatialLines", y="missing"
    x="SpatialPoints", y="missing"
    x="SpatialPolygons", y="missing"
    

    R sure does. Try, for an example:

    plot(x = 1:10)
    plot(x = 1:10, y = 10:1)
    

    And then go have a look at how the function accomplishes that, by typing plot.default.

    In general, the best way to learn how implement this kind of thing yourself will be to spend some time poking around in the code used to define functions whose behavior is already familiar to you.

    Then, if you want to explore more sophisticated forms of method dispatch, you’ll want to look into both the S3 and S4 class systems provided by R.

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

Sidebar

Related Questions

Does the C standard support something similar to __func__ for the function arguments' names?
Possible Duplicates: function overloading in C Does C support overloading ? Can anyone explain
C does not support function overloading. How can we then have 3 prototypes for
Does SQLite support seeding the RANDOM() function the same way MySQL does with RAND()
Google Spreadsheets currently does not support the standard function TDIST - i.e. the Student's
C++ does not support nested function. Say I have function a and b, I
Does jquery support both function pageload() and $().ready() ? Or is pageload() for ajax.net
Does JavaScript support garbage collection? For example, if I use: function sayHello (name){ var
I know that IE does not support pushState, but I want a way for
Does JS support two functions with the same name and different parameters ? function

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.