Confused about R terminology: Attributes, parameters, and arguments

Once and for all, I want to get the correct terminology of R. However, none of the books that I read helped, and it seems to me that authors sometimes choose names arbitrarily. So my question is when exactly are the names "attribute", "parameter" and "argument" used?

From what I have read and understood so far, a parameter is what a function can accept as input. For example, if I have a function that calculates the sum of two values, sum(value1, value2) , 'value1' and 'value2' are the parameters of the function.

If we call a function, we call the values ​​passed to the arguments to the function. For example, function sums "23" and "48" will be function arguments for:

 sum(23,48). 

Thus, basically we call it a parameter when we define a function, and call it an argument when the function is called (therefore, the arguments are passed to the function parameters)

But what about the "attributes"? As far as I understand, attributes are the equivalent of parameters in methods (and methods are functions of a class object)?

For example, if I had something like:

 heatmap(myData, Colv=NA, Rowv=NA) 

... will myData be an argument or attribute? What about Colv=NA and Rowv=NA ? Is heatmap () a function, and therefore should everything in brackets be called arguments?

+4
source share
4 answers

Let's pretend that:

 f <- function(x) x + 1 comment(f) <- "my function" f(3) 

Arguments We distinguish between formal arguments and actual arguments. The above x has a formal argument f . The formal argument names f are given as follows:

 > names(formals(f)) [1] "x" 

Actual function arguments vary from one call to another, and in the example above there is one actual argument 3 .

The args function can be used to display the entire functional signature of the function, including formal arguments and default arguments, and if you are debugging the function, you can enter match.call() to list the signature of the function with the actual arguments replaced.

Attributes The attributes of an object R are defined using attributes(f) as follows:

 > attributes(f) $srcref function(x) x + 1 $comment [1] "my function" 

There is one exception, and that the class of the object is also considered as an attribute, but not specified above, but the class is specified:

 > class(f) [1] "function" 

Parameters Sometimes function arguments are called parameters, or sometimes they refer to those arguments that are fixed as parameters, but this is usually more related to math and statistics than R.

In statistical models, the model usually depends on the data and model parameters, often in probability. For example, here:

 > lm(demand ~ Time, BOD) Call: lm(formula = demand ~ Time, data = BOD) Coefficients: (Intercept) Time 8.521 1.721 

coefficients of linear regression of interception and time (t. 8.521 and 1.721) are often referred to as model parameters.

As Dwin already pointed out, various values ​​that affect the graphics in R are also called parameters and can be displayed through:

 > par() 

and related concepts in other R-graphics systems are also often referred to as parameters.

+11
source

I suggest that the colloquial use of the term “attribute” may refer to several functions of data objects, but in R. there is a very specific meaning. An attribute is the value returned by any functions: attributes or attr , They are crucial for the language in these classes, and names are stored as attributes. There are two other assignment functions: attributes<- and attr<- , which allow you to assign additional attributes to support the goals of the class.

 ?attributes ?attr 

There is a par function that sets graphical “parameters” that control the underlying graphical behavior. Thus, this will be an R-specific use of the parameter, which may slightly differ from the use of the argument, which is usually applied to formal arguments for functions.

 ?par 

This is the args function, which is applied to the name of the function or anonymous function, will return its arguments (like a “close”, which will be printed to the console in the same way as the user will enter during the definition of the function) along with their default values. The formals function returns the same “argument” information as a list.

 ?args ?formals 

I understand that I am implicitly arguing with Matthew, whose R skills are superb. Contrary to him, I think that attributes and arguments have more specific meanings in the context of R and that cautious authors will try to keep their meanings separate. I would not have a problem understanding who uses parameter as a synonym for an argument if the context explicitly discussed the use of the function, since this is a typical language in mathematics. I agree with the conclusion of your last sentence. These are “arguments” and most categorically not attributes. The attributes of the object returned by the heatmap are:

  > attributes(hv) #from first example in ?heatmap #$names # [1] "rowInd" "colInd" "Rowv" "Colv" 

But only some of the arguments became attributes, and then only after being assigned to the return value during function execution.

+5
source

I'm not sure how similar R is to Python, but I think most terms should be consistent across languages. From what I read and learned in the last couple of days, the parameter - this is basically what the function takes as input when it is defined :

 my_function <- function (param1, param2){ ... } 

and it is called an argument if you call a function with specific input values ​​(which are passed to the function as parameters):

 my_function(arg1, arg2) 

Functions that are part of a class are called a method . And attribute can be either a value or a method associated with a class object (or a so-called instance )

So the question of whether we call something an argument or an attribute depends on what we call a function or method. But I would say that now the argument is a suitable term if we call the heatmap function, for example:

 heatmap(my_data) 
0
source

Attribute : properties of an object, for example. Man has String fName, lName;

Parameter : appears in the definition of a function / method, for example. public void setName ( fName , lName )

Argument : the value passed to the method / function parameter when calling / invoking a method / function, for example. myPerson.setName (" Michael ", " Jackson" )

0
source

All Articles