Are there best/recommended practices to follow when renaming functions in a new version of a package?

前端 未结 4 1079
执念已碎
执念已碎 2021-01-30 01:17

I\'m updating an old package and shortening a bunch of really long function names. How do I let a user know the the old function has been deprecated? I document everything with

4条回答
  •  爱一瞬间的悲伤
    2021-01-30 01:35

    I had this problem for some time and was unable to find a good solution. Then I found this. Still, the above answers are overly complicated for the simple case where one just wants to: 1) add an alias so that older code doesn't stop working, 2) the alias must work with the built-in documentation, and 3) it should be done with roxygen2.

    First, add a copy of the function:

    old_function_name = new_function_name
    

    Then, where new_function_name() is defined, add to the roxygen2:

    #' @export new_function_name old_function_name
    #' @aliases old_function_name
    

    Now the old function works because it is just a copy of the new function, and the documentation works because you set up the alias. The old version is also exported because it is included in the @export.

提交回复
热议问题