R: How do I add an extra function to a package?

后端 未结 2 1155
轻奢々
轻奢々 2021-02-09 13:56

I would like to add an idiosyncratically modified function to package written by someone else, with an R Script, i.e. just for the session, not permanently. The specific example

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 14:22

    When I am hacking on a function in a particular package that in turn calls other functions I often use this form after the definition:

    mod_func <- function( args) {body hacked}
    environment(mod_func) <- environment(old_func)
    

    But I think the function you might really want is assignInNamespace. These methods will allow the access to non-exported functions in loaded packages. They will not however succeed if the package is not loaded. So you may want to have a stopifnot() check surrounding require(pkgname).

提交回复
热议问题