[R-sig-ins] Hacking on the ChainLadder package?

Romain Francois romain.francois at dbmail.com
Wed Oct 21 09:07:03 CEST 2009


On 10/21/2009 08:56 AM, Ben wrote:
>
> Thank you very much Romain, these commands work.  I thought R (being
> an interpreted language, and no part of this package needs
> compilation) might have a short-cut to reload a module without
> installing, but it really doesn't matter because the build/install
> process runs in a few seconds on my computer anyway.

It's not actually compilation. It just sort of organize the files, 
archive them, ... there is currently no compilation in byte code or 
anything.

> I can also source individual files as you mentioned.  Although if I
> understand correctly, I need to be careful with that because the
> sourced files will affect the bindings in a different namespace than
> the original package.  Hmm, to continue with this thought, I guess I
> could just write a file that sources all the files in the package;
> that way I think I could just source the file I changed and the other
> files, because they were installed in the default namespace, would
> read the changed file.

Then you want to have a look at ?assignInNamespace or ?sys.source (untested)

sys.source( "Triangle.R", env = asNamespace( "ChainLadder" ) )

It probably won't work because the bindings in the namespace are 
probably locked, so you might want to unlock them first :

NAMESPACE <- asNamespace("ChainLadder")
sapply( ls( envir = NAMESPACE ), unlockBinding, env = NAMESPACE )
sys.source( "Triangle.R", env = asNamespace( "ChainLadder" ) )

But all of this is quite dangerous and won't work if the package uses 
various kinds of NAMESPACE trickery, etc ... but for packages with just 
standard functions, it might work.

> Thanks again,
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos



More information about the R-SIG-insurance mailing list