Thank you Ivan, your example solves my issue this time through

debug(environment(Adder$add)$add)


Just for the future, you say

    Moreover, `g` doesn't exist at all until f() is evaluated and reaches
    this point. If `f` was a function, it would be possible to trace() it,
    inserting a call to debug(g) after it's created.

How should I call trace() if f was a function?


Best regards,
Iago

________________________________
De: Ivan Krylov <ikry...@disroot.org>
Enviat el: divendres, 12 d��abril de 2024 14:38
Per a: Iago Gin�� V��zquez <iago.g...@sjd.es>
A/c: r-help@r-project.org <r-help@r-project.org>
Tema: Re: [R] Debugging functions defined (locally) inside another functions

�� Fri, 12 Apr 2024 12:15:07 +0000
Iago Gin�� V��zquez <iago.g...@sjd.es> ��ڧ�֧�:

> f <- function(whatever){
>    ...
>    g <- function(whatever2){
>      ...
>    }
>    ...
> }
>
> If I wanted to debug some thing directly inside f I would do
> debug(f). But this does not go inside g code. On the other hand,
> debug(g) does not work as g is not a defined function in the
> namespace of the package.

Moreover, `g` doesn't exist at all until f() is evaluated and reaches
this point. If `f` was a function, it would be possible to trace() it,
inserting a call to debug(g) after it's created.

> f <- ggplot2::ggproto(...)
>
> So debug(f) produces
> Error in debug(f) : argument must be a function

Can you show more information about the call that produces `f`? Where
does `g` come into play? Following ?ggplot2::ggproto, I can trigger the
browser if I reach into the environment of the publicly available
method:

Adder <- ggproto(...) # from the example
debug(environment(Adder$add)$add)
Adder$add(1234)
# debugging in: add(..., self = self)
# debug �ߧ� #3: {
#     self$x <- self$x + n
#     self$x
# }

--
Best regards,
Ivan

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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