-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider syntax for assigning intermediate value to symbol #37
Comments
A draft syntax is like x %>>% (~ symbol)
x %>>% (~ f(.) ~ symbol)
x %>>% (~ x ~ f(x) ~ symbol) It can be best described by Start with An example is mtcars %>>%
subset(mpg <= mean(mpg)) %>>%
(~ smtcars) %>>%
(~ dim(.) ~ dim_mtcars) %>>%
subset(select = c(mpg, wt, qsec)) %>>%
lm(formula = mpg ~ .) %>>%
summary %>>%
(~ summ) %>>%
(coefficients)
Inspect the environment after evaluating the code above.
|
Given all syntax with |
Consider the |
The following code adopts the mtcars %>>%
subset(mpg <= mean(mpg)) %>>%
(~ smtcars) %>>% # side-effect assign
(~ dim_mtcars = dim(.)) %>>% # side-effect assign
subset(select = c(mpg, wt, qsec)) %>>%
lm(formula = mpg ~ .) %>>%
(sum_lm = summary(.)) %>>% # eval and assign
(coefficients) |
Definitely prefer this. I think this is much clearer, intuitive, and more readable. |
Think so too. Thanks @yanlinlin82 for the great suggestion. I'll implement it at branch |
The latest commit at
That is, the assignment no longer calls |
That is more powerful! |
In v0.5, |
It's a common demand that an intermediate result be assigned to a symbol in the current environment (often global environment) for further use. This clearly is one type of side effect that the current environment is changed.
Currently, there's no easy syntax that supports the assignment operation but manually call
assign()
likeThe code works but it is only easy for global environment or some named environment. For local environment, it does not work with
parent.frame()
.Consider a syntax that derives from side-effect syntax that performs assignment operation like this.
The text was updated successfully, but these errors were encountered: