Re: [Rd] do.call and double-colon access

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 27 Jul 2004 - 06:07:36 EST


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@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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
Received on Tue Jul 27 06:12:20 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:03 EST