Skip to content
Prev 306353 / 398506 Next

specifying arguments in functions and calling functions, within functions

Hi,

You have some basic confusion here, and a problem likely caused by an
object named scl that exists in your global environment.
On Wed, Sep 26, 2012 at 11:56 AM, K. Brand <k.brand at erasmusmc.nl> wrote:
Those are double quotes, not apostrophes, and they don't have that effect:
[1] NA
Error in Scale(ex, method = "median") : could not find function "scl"
You probably have something named scl in your global environment: you
can see that with ls().

Take a look at:
[1] "function"
[1] "character"

In your first example, you're passing a function to Scale(), which
gives it a new name then uses it. In the second you're passing a
character string that happens to be the name of a function, which
Scale() gives a new name and then tries but fails to use (because it
isn't a function).

See also:
Error in Scale(ex, "Nothing") : could not find function "scl"
Depends on whether you want to pass a function or the name of a function.
You can pass them explicitly as named arguments, or with ... as you
try. In either case you have to hand those off to the function you
want to use them:

Scale <- function(x, method=c("mean", "median"),...) {
   scl <- method
    scl(x, ...)
}

Scale <- function(x, method=c("mean", "median"), na.rm=FALSE) {
   scl <- method
    scl(x, na.rm=na.rm)
}
Many functions that come with R are written purely in R and use these
capabilities so you can look at them for examples.

Sarah