Git Product home page Git Product logo

oldie's Introduction

oldie

Build Status Coverage status Stability

oldie has been archived. It is replaced by the lifecycle package.

Overview

This is an experimental package for deprecation of functions and arguments. Deprecation is spread over several releases with three levels of deprecation:

  • Soft-deprecated: This is the first stage of deprecation. The function or argument continues to work normally without any warning. Soft-deprecated functions will generally not be documented, and should not be used in examples or package code. They are left around so that existing code continues to work, but new code should not use them.

  • Deprecated: The function or argument now issues a warning when used or supplied. Users should upgrade their code to use the suggested replacement, if any.

  • Defunct: The function or argument now issues an error when used or supplied.

The deprecation levels can be promoted by calling promote_retirement(). The testthat and the strict packages will probably automatically promote the deprecation levels to make sure you are not using any soft-deprecated functions in your code.

Retirement

Functions

Let's create an obsolete function to illustrate how to retire it:

old_fn <- function() "old"

retire() is a function operator that takes a function and modifies it so that it automatically calls oldie::signal_retired(). It takes as second argument a release cycle:

old_fn <- retire(old_fn, c("0.1.0", "0.3.0", "0.5.0"))

In this release cycle the function is soft-deprecated from version 0.1.0 until 0.3.0. During that period it signals a simple condition. Between 0.3.0 and 0.5.0 it is deprecated and signals a warning. After 0.5.0 it is defunct and issues an error.

If you supply a single version, oldie completes it on the assumption that each minor version increases the deprecation level. The following expressions are thus equivalent:

retire(old_fn, "0.1.0")
retire(old_fn, c("0.1.0", "0.2.0", "0.3.0"))

If there is a new function that you can suggest as replacement, supply its name as third argument:

retire(old_fn, "0.1.0", "new_fn")

# If it lives in another package make it clear with a namespace:
retire(old_fn, "0.1.0", "pkg::new_fn")

Arguments

When retire() is supplied named arguments it deprecates the function arguments rather than the function itself:

fn <- function(..., old, new) NULL

# This deprecates the argument `old` with no replacement
retire(fn, "0.1.0", old =)

# This deprecates the argument `old` with replacement `new`
retire(fn, "0.1.0", old = new)

If a user supplies the retired argument, two things happen:

  • A deprecation signal is sent. The signal follows the same rule as for function deprecation.

  • The value supplied to the deprecated argument is reassigned to the replacement, if there is one.

Note that the retired argument is automatically added to the function formals if it's not there. This makes the code cleaner because retired arguments don't need to clutter the function definition:

fn <- function(..., new) NULL
retire(fn, "0.1.0", old =)

However this might not be appropriate if the deprecated argument originally appeared before .... In that case the argument order might not be backward compatible.

oldie's People

Contributors

lionel- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

oldie's Issues

Better print method

Indicate if function or argument is deprecated, at which stage, and since when.

Experimental features

Do we want experimental functions used from a package to throw a warning unless the package has explicitly opted in to use it?

  • Check that closure env of a function that has called the experimental function is a namespace, get the namespace name
  • Check that the package has called lifecycle::use_experimental("rlang", "experimental_fn")

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.