Closed renkun-ken closed 9 years ago
It seems a little redundant with cat() string as:
mtcars %>>%
"Sample data" %>>%
(? head(., 3))
By the way, will it be possible to support it as ternary operator?
mtcars %>>%
(mpg >= 20 ? "faster" : "slower")
@yanlinlin82 I thought about supporting the commonly used bool ? a : b
pattern but I still need to think about it and see if it brings unintentional problems.
The main consideration to support ?
as binary operator is that in a long complicated pipeline, the question expression can be ambiguous if user cannot mark the expression with string. For example,
pipeline({
mtcars
? nrow(.)
subset(mpg >= quantile(mpg, 0.05) & mpg <= quantile(mpg, 0.95))
? nrow(.)
lm(formula = mpg ~ wt + cyl)
summary
? .$r.squared
coef
})
? nrow(.)
[1] 32
? nrow(.)
[1] 28
? .$r.squared
[1] 0.8252262
Estimate Std. Error t value Pr(>|t|)
(Intercept) 36.630834 1.6127431 22.713372 3.299463e-18
wt -2.528175 0.7657771 -3.301450 2.894825e-03
cyl -1.418216 0.3533452 -4.013684 4.783302e-04
The output answers the same question in different context but user may not well distinguish the answers clearly. So a customizable label of question can be useful here.
pipeline({
mtcars
"Total number of records" ? nrow(.)
subset(mpg >= quantile(mpg, 0.05) & mpg <= quantile(mpg, 0.95))
"Qualified number of records" ? nrow(.)
lm(formula = mpg ~ wt + cyl)
summary
"R Squared" ? .$r.squared
coef
})
? Total number of records
[1] 32
? Qualified number of records
[1] 28
? R Squared
[1] 0.8252262
Estimate Std. Error t value Pr(>|t|)
(Intercept) 36.630834 1.6127431 22.713372 3.299463e-18
wt -2.528175 0.7657771 -3.301450 2.894825e-03
cyl -1.418216 0.3533452 -4.013684 4.783302e-04
The output is clearer in its own.
Whether to support question mark as ternary operator deserves another issue. I'll open one for that.
Love this idea
Alex Bresler
ASBC LLLC asbcllc.com 917-455-0239
abresler@asbcllc.com @abresler On Nov 16, 2014 8:40 PM, "Kun Ren" notifications@github.com wrote:
The main consideration to support ? as binary operator is that in a long complicated pipeline, the question expression can be ambiguity if user cannot mark the expression with string. For example,
pipeline({ mtcars ? nrow(.) subset(mpg >= quantile(mpg, 0.05) & mpg <= quantile(mpg, 0.95)) ? nrow(.) lm(formula = mpg ~ wt + cyl) summary ? .$r.squared coef })
? nrow(.) [1] 32 ? nrow(.) [1] 28 ? .$r.squared [1] 0.8252262 Estimate Std. Error t value Pr(>|t|) (Intercept) 36.630834 1.6127431 22.713372 3.299463e-18 wt -2.528175 0.7657771 -3.301450 2.894825e-03 cyl -1.418216 0.3533452 -4.013684 4.783302e-04
The output answers the same question in different context but user may not well distinguish the answers clearly. So a customizable label of question can be useful here.
pipeline({ mtcars "Total number of records" ? nrow(.) subset(mpg >= quantile(mpg, 0.05) & mpg <= quantile(mpg, 0.95)) "Qualified number of records" ? nrow(.) lm(formula = mpg ~ wt + cyl) summary "R Squared" ? .$r.squared coef })
? Total number of records [1] 32 ? Qualified number of records [1] 28 ? R Squared [1] 0.8252262 Estimate Std. Error t value Pr(>|t|) (Intercept) 36.630834 1.6127431 22.713372 3.299463e-18 wt -2.528175 0.7657771 -3.301450 2.894825e-03 cyl -1.418216 0.3533452 -4.013684 4.783302e-04
The output is clearer in its own.
— Reply to this email directly or view it on GitHub https://github.com/renkun-ken/pipeR/issues/62#issuecomment-63250741.
The current implementation only supports interpreting question mark as unary operator. For example,
Add support of question mark as binary operator so that user can customize the text in the question.
The question can be written like a mutated string.