debug only top level function

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

debug only top level function

PIKAL Petr
Dear all

I have a question about debug function. I did not use it for long time but my vague memory tell me, that when I used  debug(myfunction) in past, only myfunction was debugged and browser ignored any embedded function.

example (simple)

fff <- function(x) mean(x, na.rm=T)

when I issue
> debug(fff)
> fff(1:10)
debugging in: fff(1:10)
debug at #1: mean(x, na.rm = T)
Browse[2]>
debugging in: mean(x, na.rm = T)
debug: UseMethod("mean")
Browse[3]>
debugging in: mean.default(x, na.rm = T)
...
it starts debugging mean function. I understand that it is indicated by Browse[n] but it could be quite messy if I have many embedded functions and difficult to follow.

Can I persuade debug function not to bother with embedded functions (e.g. mean, median, mad, ...) and debug only my top level code?

Best regards
Petr

> sessionInfo()
R Under development (unstable) (2018-03-07 r74369)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250
[3] LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C
[5] LC_TIME=Czech_Czechia.1250

attached base packages:
[1] stats     datasets  utils     grDevices graphics  methods   base

other attached packages:
[1] MASS_7.3-49     readxl_1.0.0    lattice_0.20-35 fun_0.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16     cellranger_1.1.0 grid_3.5.0       plyr_1.8.4
 [5] gtable_0.2.0     scales_0.5.0     ggplot2_2.2.1    pillar_1.2.1
 [9] rlang_0.2.0      lazyeval_0.2.1   rpart_4.1-13     tools_3.5.0
[13] munsell_0.4.3    compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2
>
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner's personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: debug only top level function

Duncan Murdoch-2
On 06/06/2019 4:55 a.m., PIKAL Petr wrote:

> Dear all
>
> I have a question about debug function. I did not use it for long time but my vague memory tell me, that when I used  debug(myfunction) in past, only myfunction was debugged and browser ignored any embedded function.
>
> example (simple)
>
> fff <- function(x) mean(x, na.rm=T)
>
> when I issue
>> debug(fff)
>> fff(1:10)
> debugging in: fff(1:10)
> debug at #1: mean(x, na.rm = T)
> Browse[2]>
> debugging in: mean(x, na.rm = T)
> debug: UseMethod("mean")
> Browse[3]>
> debugging in: mean.default(x, na.rm = T)
> ...
> it starts debugging mean function. I understand that it is indicated by Browse[n] but it could be quite messy if I have many embedded functions and difficult to follow.
>
> Can I persuade debug function not to bother with embedded functions (e.g. mean, median, mad, ...) and debug only my top level code?

There are several commands available.  Type "help" to see them:

n          next
s          step into
f          finish
c or cont  continue
Q          quit
where      show stack
help       show help
<expr>     evaluate expression


You want "n", and are getting "s".  I believe if you hit Enter without
choosing one, it will do the same as the previous time, so you've
probably used "s" sometime in the past.

Duncan Murdoch

>
> Best regards
> Petr
>
>> sessionInfo()
> R Under development (unstable) (2018-03-07 r74369)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 17763)
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250
> [3] LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C
> [5] LC_TIME=Czech_Czechia.1250
>
> attached base packages:
> [1] stats     datasets  utils     grDevices graphics  methods   base
>
> other attached packages:
> [1] MASS_7.3-49     readxl_1.0.0    lattice_0.20-35 fun_0.1
>
> loaded via a namespace (and not attached):
> [1] Rcpp_0.12.16     cellranger_1.1.0 grid_3.5.0       plyr_1.8.4
>   [5] gtable_0.2.0     scales_0.5.0     ggplot2_2.2.1    pillar_1.2.1
>   [9] rlang_0.2.0      lazyeval_0.2.1   rpart_4.1-13     tools_3.5.0
> [13] munsell_0.4.3    compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2
>>
> Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner's personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
> D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: debug only top level function

PIKAL Petr
Thanks Duncan.

I think you found it. I have an object called s within my function. I wanted to check it, so I hit "s". This did not bring the object but instead it change behaviour of debug function. I did not find this in help pages nor in R exts or R intro manual. Maybe it would be worth considering to add something about it to debug help page.

Best regards
Petr

> -----Original Message-----
> From: Duncan Murdoch <[hidden email]>
> Sent: Thursday, June 6, 2019 11:11 AM
> To: PIKAL Petr <[hidden email]>; [hidden email]
> Subject: Re: [R] debug only top level function
>
> On 06/06/2019 4:55 a.m., PIKAL Petr wrote:
> > Dear all
> >
> > I have a question about debug function. I did not use it for long time but my
> vague memory tell me, that when I used  debug(myfunction) in past, only
> myfunction was debugged and browser ignored any embedded function.
> >
> > example (simple)
> >
> > fff <- function(x) mean(x, na.rm=T)
> >
> > when I issue
> >> debug(fff)
> >> fff(1:10)
> > debugging in: fff(1:10)
> > debug at #1: mean(x, na.rm = T)
> > Browse[2]>
> > debugging in: mean(x, na.rm = T)
> > debug: UseMethod("mean")
> > Browse[3]>
> > debugging in: mean.default(x, na.rm = T) ...
> > it starts debugging mean function. I understand that it is indicated by
> Browse[n] but it could be quite messy if I have many embedded functions and
> difficult to follow.
> >
> > Can I persuade debug function not to bother with embedded functions (e.g.
> mean, median, mad, ...) and debug only my top level code?
>
> There are several commands available.  Type "help" to see them:
>
> n          next
> s          step into
> f          finish
> c or cont  continue
> Q          quit
> where      show stack
> help       show help
> <expr>     evaluate expression
>
>
> You want "n", and are getting "s".  I believe if you hit Enter without choosing
> one, it will do the same as the previous time, so you've probably used "s"
> sometime in the past.
>
> Duncan Murdoch
>
> >
> > Best regards
> > Petr
> >
> >> sessionInfo()
> > R Under development (unstable) (2018-03-07 r74369)
> > Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
> > x64 (build 17763)
> >
> > Matrix products: default
> >
> > locale:
> > [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250 [3]
> > LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C [5]
> > LC_TIME=Czech_Czechia.1250
> >
> > attached base packages:
> > [1] stats     datasets  utils     grDevices graphics  methods   base
> >
> > other attached packages:
> > [1] MASS_7.3-49     readxl_1.0.0    lattice_0.20-35 fun_0.1
> >
> > loaded via a namespace (and not attached):
> > [1] Rcpp_0.12.16     cellranger_1.1.0 grid_3.5.0       plyr_1.8.4
> >   [5] gtable_0.2.0     scales_0.5.0     ggplot2_2.2.1    pillar_1.2.1
> >   [9] rlang_0.2.0      lazyeval_0.2.1   rpart_4.1-13     tools_3.5.0
> > [13] munsell_0.4.3    compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2
> >>
> > ______________________________________________
> > [hidden email] 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.
> >

Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: debug only top level function

Duncan Murdoch-2
On 06/06/2019 6:00 a.m., PIKAL Petr wrote:
> Thanks Duncan.
>
> I think you found it. I have an object called s within my function. I wanted to check it, so I hit "s". This did not bring the object but instead it change behaviour of debug function. I did not find this in help pages nor in R exts or R intro manual. Maybe it would be worth considering to add something about it to debug help page.

It's in the ?browser help page, which is linked from ?debug.

Duncan Murdoch

>
> Best regards
> Petr
>
>> -----Original Message-----
>> From: Duncan Murdoch <[hidden email]>
>> Sent: Thursday, June 6, 2019 11:11 AM
>> To: PIKAL Petr <[hidden email]>; [hidden email]
>> Subject: Re: [R] debug only top level function
>>
>> On 06/06/2019 4:55 a.m., PIKAL Petr wrote:
>>> Dear all
>>>
>>> I have a question about debug function. I did not use it for long time but my
>> vague memory tell me, that when I used  debug(myfunction) in past, only
>> myfunction was debugged and browser ignored any embedded function.
>>>
>>> example (simple)
>>>
>>> fff <- function(x) mean(x, na.rm=T)
>>>
>>> when I issue
>>>> debug(fff)
>>>> fff(1:10)
>>> debugging in: fff(1:10)
>>> debug at #1: mean(x, na.rm = T)
>>> Browse[2]>
>>> debugging in: mean(x, na.rm = T)
>>> debug: UseMethod("mean")
>>> Browse[3]>
>>> debugging in: mean.default(x, na.rm = T) ...
>>> it starts debugging mean function. I understand that it is indicated by
>> Browse[n] but it could be quite messy if I have many embedded functions and
>> difficult to follow.
>>>
>>> Can I persuade debug function not to bother with embedded functions (e.g.
>> mean, median, mad, ...) and debug only my top level code?
>>
>> There are several commands available.  Type "help" to see them:
>>
>> n          next
>> s          step into
>> f          finish
>> c or cont  continue
>> Q          quit
>> where      show stack
>> help       show help
>> <expr>     evaluate expression
>>
>>
>> You want "n", and are getting "s".  I believe if you hit Enter without choosing
>> one, it will do the same as the previous time, so you've probably used "s"
>> sometime in the past.
>>
>> Duncan Murdoch
>>
>>>
>>> Best regards
>>> Petr
>>>
>>>> sessionInfo()
>>> R Under development (unstable) (2018-03-07 r74369)
>>> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
>>> x64 (build 17763)
>>>
>>> Matrix products: default
>>>
>>> locale:
>>> [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250 [3]
>>> LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C [5]
>>> LC_TIME=Czech_Czechia.1250
>>>
>>> attached base packages:
>>> [1] stats     datasets  utils     grDevices graphics  methods   base
>>>
>>> other attached packages:
>>> [1] MASS_7.3-49     readxl_1.0.0    lattice_0.20-35 fun_0.1
>>>
>>> loaded via a namespace (and not attached):
>>> [1] Rcpp_0.12.16     cellranger_1.1.0 grid_3.5.0       plyr_1.8.4
>>>    [5] gtable_0.2.0     scales_0.5.0     ggplot2_2.2.1    pillar_1.2.1
>>>    [9] rlang_0.2.0      lazyeval_0.2.1   rpart_4.1-13     tools_3.5.0
>>> [13] munsell_0.4.3    compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2
>>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>
> Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: debug only top level function

Martin Maechler
>>>>> Duncan Murdoch
>>>>>     on Thu, 6 Jun 2019 07:38:40 -0400 writes:

    > On 06/06/2019 6:00 a.m., PIKAL Petr wrote:
    >> Thanks Duncan.
    >>
    >> I think you found it. I have an object called s within my function. I wanted to check it, so I hit "s". This did not bring the object but instead it change behaviour of debug function. I did not find this in help pages nor in R exts or R intro manual. Maybe it would be worth considering to add something about it to debug help page.

    > It's in the ?browser help page, which is linked from ?debug.

    > Duncan Murdoch

Indeed.
As it is not the first time, users did not "find" this, I have
made the links a bit more visible (for future R versions), now.

I'd  use  '(s)'  instead of 's'  [and more often and
importantly, I have a variable 'n' somewhere and need to use
'(n)'  very regularly.

For smallish situations, btw, the use of   ls.str()  comes very handy.

It has to be noted that unfortunately, the difference between
'n' and 's' and 'c'  has been a bit "blurred" for byte compiled
functions, and as the default JIT level is high, I had
occasionallz wanted an easy way to revert the byte compilation
before debugging.... or another way to get rid of this
drawback..

Martin



    >>
    >> Best regards
    >> Petr
    >>
    >>> -----Original Message-----
    >>> From: Duncan Murdoch <[hidden email]>
    >>> Sent: Thursday, June 6, 2019 11:11 AM
    >>> To: PIKAL Petr <[hidden email]>; [hidden email]
    >>> Subject: Re: [R] debug only top level function
    >>>
    >>> On 06/06/2019 4:55 a.m., PIKAL Petr wrote:
    >>>> Dear all
    >>>>
    >>>> I have a question about debug function. I did not use it for long time but my
    >>> vague memory tell me, that when I used  debug(myfunction) in past, only
    >>> myfunction was debugged and browser ignored any embedded function.
    >>>>
    >>>> example (simple)
    >>>>
    >>>> fff <- function(x) mean(x, na.rm=T)
    >>>>
    >>>> when I issue
    >>>>> debug(fff)
    >>>>> fff(1:10)
    >>>> debugging in: fff(1:10)
    >>>> debug at #1: mean(x, na.rm = T)
    >>>> Browse[2]>
    >>>> debugging in: mean(x, na.rm = T)
    >>>> debug: UseMethod("mean")
    >>>> Browse[3]>
    >>>> debugging in: mean.default(x, na.rm = T) ...
    >>>> it starts debugging mean function. I understand that it is indicated by
    >>> Browse[n] but it could be quite messy if I have many embedded functions and
    >>> difficult to follow.
    >>>>
    >>>> Can I persuade debug function not to bother with embedded functions (e.g.
    >>> mean, median, mad, ...) and debug only my top level code?
    >>>
    >>> There are several commands available.  Type "help" to see them:
    >>>
    >>> n          next
    >>> s          step into
    >>> f          finish
    >>> c or cont  continue
    >>> Q          quit
    >>> where      show stack
    >>> help       show help
    >>> <expr>     evaluate expression
    >>>
    >>>
    >>> You want "n", and are getting "s".  I believe if you hit Enter without choosing
    >>> one, it will do the same as the previous time, so you've probably used "s"
    >>> sometime in the past.
    >>>
    >>> Duncan Murdoch
    >>>
    >>>>
    >>>> Best regards
    >>>> Petr
    >>>>
    >>>>> sessionInfo()
    >>>> R Under development (unstable) (2018-03-07 r74369)
    >>>> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
    >>>> x64 (build 17763)
    >>>>
    >>>> Matrix products: default
    >>>>
    >>>> locale:
    >>>> [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250 [3]
    >>>> LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C [5]
    >>>> LC_TIME=Czech_Czechia.1250
    >>>>
    >>>> attached base packages:
    >>>> [1] stats     datasets  utils     grDevices graphics  methods   base
    >>>>
    >>>> other attached packages:
    >>>> [1] MASS_7.3-49     readxl_1.0.0    lattice_0.20-35 fun_0.1
    >>>>
    >>>> loaded via a namespace (and not attached):
    >>>> [1] Rcpp_0.12.16     cellranger_1.1.0 grid_3.5.0       plyr_1.8.4
    >>>> [5] gtable_0.2.0     scales_0.5.0     ggplot2_2.2.1    pillar_1.2.1
    >>>> [9] rlang_0.2.0      lazyeval_0.2.1   rpart_4.1-13     tools_3.5.0
    >>>> [13] munsell_0.4.3    compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2

______________________________________________
[hidden email] 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.