[R-pkg-devel] Browser Level for Conditional Function Parameter

Duncan Murdoch murdoch.duncan at gmail.com
Thu Aug 20 14:20:11 CEST 2015


On 20/08/2015 1:00 AM, Dario Strbenac wrote:
> Good day,
> 
> Why do I get a debug message and a change in browser level when I inspect the title variable ? For the comparison variable, it simply prints its value and remains at level 1.

This is an R-devel question, not an R-pkg-devel question.

You get the break there because displaying title requires code to be
evaluated (the default value is an expression), and the browser will
break while evaluating that code.  The "debug" message comes because it
is on line 4 of your function that it is breaking.  If it had been in a
file that you sourced, it would give the line number from that file.

Duncan Murdoch

> aFunction <- function(comparison = c("within", "classifier", "selection"),
>                       title = if(comparison[1] == "within") "Internal" else "Between")
> {
>     browser()
>     require(ggplot2)
>     comparison <- match.arg(comparison)
>     ggplot(mtcars, aes(wt, mpg)) + geom_point() + ggtitle(title)
> }
> 
> aFunction()
> 
> Browse[1]> title
> debug at #4: [1] "Internal"
> Browse[3]>
> 
> --------------------------------------
> Dario Strbenac
> PhD Student
> University of Sydney
> Camperdown NSW 2050
> Australia
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list