Comments (6)
After some digging, this seems to work:
# roxygen documentation here
# @export
somefunc <- function(continue, x) {
x * continue
}
# save the latter
somefunc.call <- somefunc
# intercept it
somefunc <- function(...) {
# get call
caller <- sys.call()
# replace the function name
caller[[1]] <- as.name("somefunc.call")
# replace "continue" and show a warning if "merge" is found
if ("merge" %in% names(caller)) {
warning("'merge' is deprecated, use 'continue' instead")
caller$continue <- caller$merge
caller$merge <- NULL
}
# make the proper call
eval(caller)
}
somefunc(continue=2, 3)
#> [1] 6
somefunc(2, 3)
#> [1] 6
somefunc(merge=2, 3)
#> [1] 6
#> Warning message:
#> In somefunc(merge = 2, 3) : 'merge' is deprecated, use 'continue' instead
What do you think?
from simmer.
@Enchufa2, fully agree with the more intuitive naming.
What about the below snippet?
branch <- function(traj, option, continue=merge, merge=continue, ...) traj$branch(option, continue, ...)
We could then simply add to the documentation that from version x, the support for the merge
parameter would be dropped (and maybe show a warning).
from simmer.
If you are ok with the renaming, I'd prefer my scheme above. The problem is that your snippet breaks backwards compatibility. With my example, however,
- The new parameter works.
- The unnamed call works.
- The old parameter works and shows a warning.
The documentation can still describe the old parameter, saying that from version x, the support for it would be dropped.
from simmer.
Mmmmh... but my approach has problems with magrittr
pipelines...
from simmer.
What about the below?
the_func<-function(new=old, old="_deprecated"){
if(!old=="_deprecated") warning("use of 'old' is deprecated")
new
}
# new param works
the_func(new=123)
# unnamed call works
the_func(123)
# old works and shows a warning
the_func(old=123)
Haven't compared it, but I think that this might also be more performant.
from simmer.
There was a problem when the old param was used, but it's solved. Done, thanks!
from simmer.
Related Issues (20)
- Renege-timer error "not previously seized" HOT 4
- Implement arithmetic for schedules
- Use 'given' in CITATION
- Ability to deep-copy simulation environments
- synchronize() not work as expected HOT 3
- Monitors do not register the finalizer
- Dangling environment prevents object destruction HOT 1
- Bank Tutorial Part II: Balking - finished=TRUE even though balked HOT 1
- Batch cloning doesn't clone individual arrivals
- Caller misidentification
- Add support for vectors of capacities, queue sizes... HOT 2
- Airport control security HOT 1
- Option to add wait() time to activity_time
- Option to trap() "all" signals instead of "any"
- Possible Bug? `per_resource = T` drops the `finished` variable in `get_mon_arrivals()` HOT 3
- download version from CRAN does not recognise "tag" argument. HOT 6
- Output options are too limited HOT 2
- Ability to remove embeded attribute dataframes from simmer environment HOT 1
- Add getter for the arrival time
- Subset by tag
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 simmer.