[R] debug only top level function

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Thu Jun 6 16:52:35 CEST 2019


>>>>> 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 <murdoch.duncan using gmail.com>
    >>> Sent: Thursday, June 6, 2019 11:11 AM
    >>> To: PIKAL Petr <petr.pikal using precheza.cz>; r-help using r-project.org
    >>> 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



More information about the R-help mailing list