Ivan Krylov
2024-Apr-12  12:38 UTC
[R] Debugging functions defined (locally) inside another functions
? Fri, 12 Apr 2024 12:15:07 +0000 Iago Gin? V?zquez <iago.gine at 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 functionCan 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
Iago Giné Vázquez
2024-Apr-12  12:53 UTC
[R] Debugging functions defined (locally) inside another functions
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 <ikrylov at disroot.org>
Enviat el: divendres, 12 d??abril de 2024 14:38
Per a: Iago Gin?? V??zquez <iago.gine at sjd.es>
A/c: r-help at r-project.org <r-help at 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.gine at 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]]
Seemingly Similar Threads
- Debugging functions defined (locally) inside another functions
- Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line
- Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line
- Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line
- Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line