Overloading R function - is this right? -


consumesinglerequest <- function(api_key, url, columnnames, globalparam="", ...)  consumesinglerequest <- function(api_key, url, columnnames, valueslist, globalparam="") 

i trying overload function this, takes in multiple lists in first function , combines them 1 list of lists. however, don't seem able skip passing in globalparam , pass in oly multiple lists in ...

does know how that?

i've heard s3 methods used that? know how?

r doesn't support concept of overloading functions. supports function calls variable number of arguments. can declare function number of arguments, supply subset of when calling function. take vector function example:

> vector function (mode = "logical", length = 0l)  .internal(vector(mode, length)) <bytecode: 0x103b89070> <environment: namespace:base> 

it supports 2 parameters, can called none or subset(in case default values used) :

> vector() logical(0) > vector(mode='numeric') numeric(0) 

so need second declaration:

consumesinglerequest <- function(api_key, url, columnnames, valueslist, globalparam="") 

and supply supply needed parameters when calling function

consumesinglerequest(api_key=..., valuelist=...) 

p.s. explanation can found in advanced r book.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -