Comments (6)
I agree that my example using stop()
might not be so useful, but x == 2 <- ~ . * 0.7
seems readable enough to me.
Your counter proposal is hard to implement because we might genuinely want to assign a list.
My proposal has weaker assumptions as it just assumes that you would rarely want to assign a function or a formula to a list element using our assignment functions.
If you think it's confusing we can drop the feature though, and see later if we miss it.
from inops.
I agree with you about the list - we might want to assign a list, so it fails in the general case, we can discard that.
I think we also have to keep in mind the possible benefit about the shorter notations. For example, would someone be persuaded to use the package so that they can do this:
x == 2 <- ~ . * 0.7
instead of this:
x[x==2] <- x[x==2] * 0.7
Or if we provide the subset alternatives, this seems even better:
(x %subset==% 2) * 0.7
Thou even for subset this standard way seems to be the shortest:
x[x==2] * 0.7
So in my mind the question is - do we gain some advantage from the formula syntax..
You will notice that I am quite conservative when it comes to adding new syntax :) I I think you are more willing to add complex syntax and explore new ideas. Will be interesting to see how this plays out in working on this package.
from inops.
Maybe it's better to be more conservative to start with.
I like the feature because to me variable repetition comes with increased cognitive load, and the syntax x < 2 <- 42
is really just to avoid x[x < 2] <- 42
so supporting functions goes a step further in the same direction, plus with a longer variable names you can get something like :
some_df$some_var == 2 <- ~ . * 0.7 # rather than :
some_df$some_var[some_df$some_var == 2] <- some_df$some_var[some_df$some_var == 2] * 0.7
With my package dotdot I would do :
some_df$some_var[some_df$some_var == 2] := .. * 0.7
But I understand we're talking about advanced features before having the basics laid out. I'll remove it for now.
from inops.
Agreed about some_df$some_var
situation.
I am starting to like to formula solution. But maybe we can implement it without ~
and rlang dependency? So just:
some_df$some_var == 2 <- . * 0.7
And we agree to use dot as a placeholder for the x
.
from inops.
Unfortunately some_df$some_var == 2 <- . * 0.7
is not possible because foo<-
functions always evaluate the rhs before even entering the function.
Making the rhs a formula was a way to use NSE here.
from inops.
Let's reopen this if we miss it later, and move forward with simpler scope
from inops.
Related Issues (20)
- README HOT 8
- consistency between in_check ops and equality/comparison ops ? HOT 8
- simplify replace ops HOT 2
- package name HOT 7
- `%in%<-`, `%out%`, `%out%<-` HOT 1
- `%in{}%` on (lists of) language objects HOT 1
- regex ops don't have the same consistency to == as other ops HOT 1
- inconsistent way of dealing with factors in `%in{}%` HOT 3
- Improve error "NAs are not allowed in subscripted assignments" in replacement functions HOT 5
- Case for replacement acting as `ifelse()` ? HOT 4
- `%#in%` family HOT 18
- add example `NA %in{}% NA` HOT 5
- CRAN issues HOT 25
- dealing with NAs HOT 6
- conflicted doesn't like inops HOT 14
- The following object is masked from ‘package:base’: <<-
- More fame and glory HOT 1
- multiple replacements HOT 5
- Operator for selecting quantile range?
- First CRAN release HOT 85
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inops.