Confused about R terminology: Attributes, parameters, and arguments

arguments, attributes, function, parameters, r

Solution

Suppose we have:

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

Arguments We distinguish between formal arguments and actual arguments. In the above `x` is the formal argument to `f`. The names of the formal arguments of `f` are given by:

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

The actual arguments to a function vary from one call to another and in the above example there is a single actual argument `3`.

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

Attributes The attributes of an R object are given by `attributes(f)` like this:

> attributes(f)
$srcref
function(x) x + 1

$comment
[1] "my function"

There is one exception and that is that an object's class is also regarded as an attribute but is not given by the above but rather is given by `class`:

> class(f)
[1] "function"

Parameters Sometimes function arguments are referred to as parameters or sometimes one refers to those arguments which are fixed as parameters but this tends to be related more to mathematics and statistics than R.

In statistical models the model is typically a function of the data and the model parameters often via the likelihood. For example, here:

> lm(demand ~ Time, BOD)

Call:
lm(formula = demand ~ Time, data = BOD)

Coefficients:
(Intercept)         Time  
      8.521        1.721  

the linear regression coefficients of Intercept and Time (viz. 8.521 and 1.721) are often referred to as model parameters.

As Dwin has already pointed out the various values influencing graphics in R are also termed parameters and can be displayed via:

> par()

and the corresponding concepts in other R graphics systems are often also referred to as parameters.

Problem

Once and for all I want to get the R terminology right. However, none of the books I was reading was of big help, and it seems to me the authors choose the names sometimes arbitrarily. So, my question is when exactly are the names "attribute", "parameter", and "argument" used? From what I read and understood so far, a parameter is what a function can take as input. For example if I have a function that calculates the sum of two values, `sum(value1, value2)`, 'value1' and 'value2' are the function's parameters. If we are calling a function, we call the values passed to the function arguments. For the sum-function example, "23" and "48" would be the function arguments for: ``` sum(23,48). ``` So basically we call it parameter when we define a function, and we call it argument when we call the function (so the arguments are passed to the function's parameters) But what about "attributes"? From what I understand, attributes are the equivalent of parameters in methods (and methods are functions of a class object)? For example, if I would have something like: ``` heatmap(myData, Colv=NA, Rowv=NA) ``` ... , would 'myData' be an argument or attribute? And what about `Colv=NA` and `Rowv=NA`? Isn't heatmap() a function and thus everything in the parentheses should be called arguments?

Original source