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

Ben misc7 at emerose.org
Fri Oct 23 03:30:08 CEST 2009


Thanks, Romain, your trick below works great for editing functions in
packages.  However, it appears that introducing a new binding to a
locked namespace/environment (are these synonyms?) fails, and
unlockBinding doesn't work because there is nothing there to unlock
yet.  e.g.,

> sys.source("MackChainLadderFunctions.R", env = asNamespace( "ChainLadder" ))
Error in eval(expr, envir, enclos) : 
  cannot add bindings to a locked environment

Is there some way to add a new function to a locked package?

Thanks,

-- 
Ben Escoto

----------------- Original message -----------------
From: Romain Francois <romain.francois at dbmail.com>
To: Ben <misc7 at emerose.org>
Date: Wed, 21 Oct 2009 09:07:03 +0200
...

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.

...

-- 
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