On Tue, 31 May 2011, Romain Francois wrote:

Hello,

assignInNamespace refuses to assign an object to a name that is not already used in the namespace.

That's intentional, and as documented:

     ‘assignInNamespace’ and ‘fixInNamespace’ are invoked for their
     side effect of changing the object in the name space.
                    ^^^^^^^^

I very much doubt we want to allow adding objects.


Something like this would make it possible:

--- src/library/utils/R/objects.R       (revision 56024)
+++ src/library/utils/R/objects.R       (working copy)
@@ -252,8 +252,9 @@
            stop("environment specified is not a package")
        ns <- asNamespace(substring(nm, 9L))
    } else ns <- asNamespace(ns)
-    if(bindingIsLocked(x, ns)) {
-        unlockBinding(x, ns)
+    new_binding <- !exists(x,ns)
+    if( new_binding || bindingIsLocked(x, ns)) {
+        if(!new_binding) unlockBinding(x, ns)
        assign(x, value, envir = ns, inherits = FALSE)
        w <- options("warn")
        on.exit(options(w))

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
http://romain-francois.com
|- http://bit.ly/hdKhCy : Rcpp article in JSS
|- http://bit.ly/elZJRJ : Montpellier Comedie Club - Avril 2011
`- http://bit.ly/fhqbRC : Rcpp workshop in Chicago on April 28th

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


--
Brian D. Ripley,                  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to