Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add previous_definition #13

Open
klmr opened this issue Oct 27, 2014 · 0 comments
Open

Add previous_definition #13

klmr opened this issue Oct 27, 2014 · 0 comments
Assignees

Comments

@klmr
Copy link
Contributor

klmr commented Oct 27, 2014

When overriding existing functions form base packages, use the following helper function to dispatch to existing functions without hard-coding their exact namespace:

previous_definition = function (name) {
    # Skip the parent environment of the calling frame.
    get(name, envir = parent.env(parent.env(parent.frame())))
}

This allows multiple redefinitions layered on top of each other (unlike e.g. devtools::help, which does this “wrong”). For an example of usage, see this Stack Overflow answer.

@klmr klmr self-assigned this Oct 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant