I am currently developing two packages, the following is a simplified version of my problem:
In package A, I have some functions (say sum_twice), and I call another function inside the package (say "slow_sum"). However, in package B, I wrote another function (say, "fast_sum"), with which I want to replace the slow function in package A.
Now, how do I manage this "override" of the "slow_sum" function using the fast_sum function?
Here is a simplified example of such functions (just for illustration):
slow_sum <- function(x) {
sum_x <- 0
for(i in seq_along(x)) sum_x <- sum_x + x[i]
sum_x
}
sum_twice <- function(x) {
x2 <- rep(x,2)
slow_sum(x2)
}
fast_sum <- function(x) { sum(x) }
If I do something like slow_sum <- fast_sumthis, this will not work, since sum_twice uses the slow_sum from the NAMESPACE package A.
"B":
assignInNamespace(x = "slow_sum", value = B:::fast_sum, ns = "A")
, , CRAN
":", assignInNamespace
( , ).
.
"sum_twice" "fast_sum"
"Slow_sum"?
,
,
Tal
p.s: .
UDPATE:
, R ( ), dendextend ( CRAN). Rcpp ( dendextendRcpp, github). , , . , , assignInNamespace, CRAN + , CRAN ( ).
, , . , , - ( , , ). - dendextend dendextendRcpp , , . , ( , - , ). ? .