Closed renkun-ken closed 10 years ago
Currently, the side-effect syntax can be used for debugging with browser().
browser()
Suppose the original code:
mtcars %>>% subset(mpg <= quantile(mpg, 0.95)) %>>% lm(formula = mpg ~ .) %>>% summary %>>% (r.squared)
To debug this code, just insert (~ browser()) to the pipeline after the line one needs to debug. At the browser environment, one only needs to type . to see the input of that line. For example,
(~ browser())
.
mtcars %>>% subset(mpg <= quantile(mpg, 0.95)) %>>% lm(formula = mpg ~ .) %>>% (~ browser()) %>>% summary %>>% (r.squared)
The debugging looks like
Browse[1]> . Call: lm(formula = mpg ~ ., data = .) Coefficients: (Intercept) cyl disp hp drat wt 29.13001 -0.84475 0.01751 -0.02851 0.26103 -3.70579 qsec vs am gear carb 0.15113 0.15242 -0.19900 1.05332 0.10792 Browse[1]> Q >
One can also specify parameters of browser() to perform conditional browsing. For example,
mtcars %>>% subset(mpg <= quantile(mpg, 0.95)) %>>% lm(formula = mpg ~ wt + cyl) %>>% (~ browser(expr = summary(.)$r.squared >= 0.9)) %>>% plot()
To help identify the browser location, print something ahead.
mtcars %>>% subset(mpg <= quantile(mpg, 0.95)) %>>% lm(formula = mpg ~ wt + cyl) %>>% (~ print("debugging")) %>>% (~ browser()) %>>% plot()
or
mtcars %>>% subset(mpg <= quantile(mpg, 0.95)) %>>% lm(formula = mpg ~ wt + cyl) %>>% (? ~ "debugging") %>>% # print expression only (~ browser()) %>>% plot()
Currently, the side-effect syntax can be used for debugging with
browser()
.Suppose the original code:
To debug this code, just insert
(~ browser())
to the pipeline after the line one needs to debug. At the browser environment, one only needs to type.
to see the input of that line. For example,The debugging looks like
One can also specify parameters of
browser()
to perform conditional browsing. For example,To help identify the browser location, print something ahead.
or