Code Monkey home page Code Monkey logo

Comments (6)

Enchufa2 avatar Enchufa2 commented on June 8, 2024

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.

bart6114 avatar bart6114 commented on June 8, 2024

@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.

Enchufa2 avatar Enchufa2 commented on June 8, 2024

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.

Enchufa2 avatar Enchufa2 commented on June 8, 2024

Mmmmh... but my approach has problems with magrittr pipelines...

from simmer.

bart6114 avatar bart6114 commented on June 8, 2024

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.

Enchufa2 avatar Enchufa2 commented on June 8, 2024

There was a problem when the old param was used, but it's solved. Done, thanks!

from simmer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.