[R] modify functions in imported namespace in a new package

heyi xiao xiaoheyiyh at yahoo.com
Thu Jan 3 20:48:04 CET 2013


Any thoughts or suggestions? This does not seem be a trivial
issue. Thanks!

----- Original Message -----
From: heyi xiao <xiaoheyiyh at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Wednesday, January 2, 2013 3:22 PM
Subject: modify functions in imported namespace in a new package

Hello all,
I am developing an R package. My package uses several
classes and functions from another package (package A). Normally, I could just
specify package A as imports or depends in my DESCPRITION and NAMESPACE files.
One function I use is F, which calls a bunch of other
functions including G in package A. To use function F in my package, I have to
modify function G first. Therefore, I rewrite function G first and do assignInNamespace("G",
G, envir="A") in the source R file, either with or without .onLoad
function. Either way, the package was checked and installed free of error. But
after loading, my package still calls the original function G (through F) in
package A, instead of the version I supplied. 
Note that I may do assignInNamespace after my package gets
loaded in a user session, it works perfectly fine. I realize that I may
manually include in my package all the sources for relevant classes and
functions from package A and rewrite function G only. But that’s too awkward
and does not gives credit to package A.
I would really appreciate any thoughts and suggestions on
why assignInNamespace didn’t work in my source package, and how to solve it. Thanks!
Heyi




More information about the R-help mailing list