S7 and a new `:=` named-bind operator
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- r
- Domain
- developer-experience
Research direction
Start with the existing := behavior in data.table and compare it with the S7 package's proposed named-bind operator and rlang's definition. No files or tests are identified; done would require an agreed compatibility approach and a clearly specified implementation or feedback outcome.
Written by the indexing model from the issue text.
Description
The dev version of the S7 package introduces a new := operator:
`:=` <- function(lhs, rhs) {
cl <- sys.call()
if (!is.symbol(cl[[2L]])) {
stop2("Left-hand side of `:=` must be a symbol.")
}
if (!is.call(cl[[3L]])) {
stop2("Right-hand side of `:=` must be a function call.")
}
if ("name" %in% names(cl[[3L]])) {
stop2("Right-hand side of `:=` must not already supply a `name` argument.")
}
cl[[1L]] <- quote(`<-`)
cl[[3L]]$name <- as.character(cl[[2L]])
# Can't use eval because it introduces a new frame
invisible(.Call(S7_eval_bare_, cl, parent.frame()))
}
This is designed to support creating new classes and generics (and various more exotic objects) where you want to give an object a name and bind it to that name.
# with <-
foo <- new_class("foo")
bar <- new_generic("bar")
# with :=
foo := new_class()
bar := new_generic()
This feels like a useful and general tool and @lawremi thinks there's some chance it will make it to base R.
The downside is that it conflicts with the existing definitions of := in data.table and rlang which both error to suggest to the user they've done something wrong. (It doesn't actually affect the operation of these packages since both data.table and rlang override the meaning of := via NSE.)
We don't have any solutions to this problem yet (although we're experimenting with a .onLoad hook approach for rlang that we can share when it's done), but I wanted to give y'all a heads up that we're seriously exploring it and give you an opportunity to give feedback to the S7 team.
(cc @t-kalinowski)
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·