[Rd] do.call and double-colon access

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jul 26 22:07:36 CEST 2004


On Mon, 26 Jul 2004, Vincent Carey 525-2265 wrote:

> 
> Using R 2.0.0 of July 20 2004
> 
> train, test, and cl as defined in example(knn),
> 
> we have
> 
> > search()
> [1] ".GlobalEnv"       "package:methods"  "package:stats"    "package:graphics"
> [5] "package:utils"    "Autoloads"        "package:base"
> > knn(train, test, cl, k=3)
> Error: couldn't find function "knn"
> > class::knn(train, test, cl, k=3)
>  [1] s s s s s s s s s s s s s s s s s s s s s s s s s c c v c c c c c v c c c c
> [39] c c c c c c c c c c c c v c c v v v v v v v v v v c v v v v v v v v v v v
> Levels: c s v
> > do.call("class::knn", list(train=train, test=test, cl=cl, k=3))
> Error in do.call("class::knn", list(train = train, test = test, cl = cl,  :
>         couldn't find function "class::knn"
> > library(class)
> > do.call("knn", list(train=train, test=test, cl=cl, k=3))
>  [1] s s s s s s s s s s s s s s s s s s s s s s s s s c c v c c c c c v c c c c
> [39] c c c c c c c c c c c c v c c v v v v v c v v v v c v v v v v v v v v v v
> Levels: c s v
> 
> 
> should do.call("class::knn", ...) succeed?

No.  From the help page for do.call

Arguments:

    what: a character string naming the function to be called.

class::knn is a function call that get()s a function (try get("::") -- it
is really "::"("get", "class")) and not the name of a function.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list