Comments (4)
Might want to disable partial matching when a default is provided?
Good point.
Though, I can see how "magically" setting exact = TRUE
when default
is specified, can become a point of confusion and possibly result in a blocking discussion for implementing support for a new argument default
. If exact = TRUE
becomes the new default, which I hope it one day will, this would be moot.
An alternative to having the default value of exact
depend on whether argument default
i specified, is to require exact = TRUE
whenever default
is specified. This means you'd had to write:
w <- attr(x, "hello", exact = TRUE, default = "world")
for now, to avoid an error. This would also help to prepare for the day when exact = TRUE
becomes the new default (I hope).
(Just my thoughts)
from wishlist-for-r.
I like this idea - this addition to attr()
would be consistent to how getOption()
and Sys.getenv()
provide "default" fallbacks. Not sure if there are other functions too with this too.
FWIW, I wasn't sure whether NULL
was a valid attribute value. It turns out it's not; it's not possible to have attributes will value NULL
;
> x <- 42L; attributes(x) <- alist(abc = 1, def = NULL, ghi = 3)
> str(attributes(x))
List of 2
$ abc: num 1
$ ghi: num 3
In other words, one does not have to account for that as a special case and your "current" snippet is sufficient.
PS: big fan of your work. Thanks for this repository and for all your packages! smiley
Thanks. Happy to hear :)
from wishlist-for-r.
Might want to disable partial matching when a default is provided?
from wishlist-for-r.
I prefer more generic approach like this in my code
w <- ifnull(attr(x, "hello"), "world")
Would be nice to have something like this in base but the addition would potentially break someone's code of course.
from wishlist-for-r.
Related Issues (20)
- Suggested performance improvements in R HOT 1
- Separate Build-depends: from Suggests: in DESCRIPTION files HOT 9
- Allow setting breakpoints from debugger
- WISH: `drop` = FALSE by default for `[.data.frame` HOT 9
- Fast check for discreteness
- Make UTF-8 the default encoding for package metadata HOT 2
- WISH/ROBUSTNESS: Mechanism to prevent var <<- value from assigning non-existing 'var' HOT 1
- Consistency: fix matrix subsetting behaviour to be consistent with vectors and data.frames.
- Base R function for length(unique(x))
- WISH: Standardized SystemRequirements HOT 1
- `grDevices::dev.capabilities()` enhancements
- Permit larger seed argument values in set.seed() HOT 1
- Wish: base version of glue::glue() HOT 3
- Add predict method for `stats::kmeans()`
- R CMD check: Option for reporting on writes/updates to tools::R_user_dir() during checks HOT 1
- R CMD check: Option for testing with empty tools::R_user_dir() folders
- Control over `NA` equality in `base::rle()`
- WISH: Make serverSocket(0) useful (+ find a random TCP port that can be listened to) HOT 1
- Task & browser hooks to support implementation of a debug adapter protocol client
- parallel: A sequential cluster
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 wishlist-for-r.