On Fri, 11 Sep 2009 16:07:45 +0200, Gabor Grothendieck <ggrothendi...@gmail.com> wrote:

See ?assignInNamespace


thanks for the hint. It works to some extent. Functions are redefined in "base" but utils:::specialCompletions seems not to preform properly:

ls.proto <- function(x){  # function to complete
    .local <- function(x){
if(is(x[[".super"]], "proto")) c(ls.default(x), Recall(x[[".super"]]))
        else ls.default(x)
    }
    unlist(.local(x))
}

ls1 <- base::ls # cache ls

ls.default1 <- function(name, pos = -1, envir = as.environment(pos), all.names = FALSE, pattern){
    UseMethod("ls")
}

assignInNamespace("ls.default", ls1 , 'base')
assignInNamespace("ls", ls.default1 , 'base')
assignInNamespace("ls.proto", ls.proto , 'base')

environment(ls) <- asNamespace('base')
environment(ls.default) <- asNamespace('base')
environment(ls.proto) <- asNamespace('base')

p1 <- proto(p1_abc=123)
p2 <- proto(.=p1, p2_abc=23423)

ls(p2)
[1] "p2_abc" "p1_abc"   #works fine !!!!
ls(p1)
[1] "p1_abc"


Completion for $ works fine with environments and everything else, but not with proto objects.
also ls.str (which uses ls internally) gives an error.

ls.str(p1)
Error in ls(name, envir = envir, all.names = all.names, pattern = pattern) :
  argument "name" is missing, with no default


What is going on?? My ls.proto works nicely in global env but does not when called from attached packages?
Would really appreciate if someone can enlighten me.

Thanks a lot.

PS: I also tried to modify utils:::specialCompletions directly, did not wok either - it's something wrong with ls.proto above :(.

On Fri, Sep 11, 2009 at 10:02 AM, Vitalie S. <vitosm...@rambler.ru> wrote:

Hello everyone,

I am trying to implement completion for proto objects. Proto extends
environment in a hierarchical way. Thus completion should list all the names
in all it's parent environments.

For "normal" classes defining names.class would do the job, but completion for "environment" is hard coded in utils:::specialCompletions by means of
base::ls(). As result defining names.proto does not work.

I tried to make "ls" generic and to do something like:

environment(ls.default) <- asNamespace('utils')
environment(ls) <- asNamespace('utils')
environment(ls.proto) <- asNamespace('utils')

That does not work either.

Is there a way to make utils:::specialCompletions use my "ls" instead of
"base::ls"??

I know Deepayan Sarkar is working now on improving the completion system
(potentially by introducing "completion" generic). That would definitely
solve the problem. But for now, does a quick fix exist?

Thanks a lot,
Vitalie

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to