Since R has the same namespace for functions and variables,> c <- 1kills the global function, which can be restored by> c <- get("c",mode="function")Is there a way to prevent R from overriding globals or at least warning when I do that or at least warning when I replace a functional value with non-functional? thanks. -- Sam Steingold (sds.podval.org) on Ubuntu 11.10 (oneiric) X 11.0.11004000 childpsy.net iris.org.il camera.org ffii.org dhimmi.com mideasttruth.com pmw.org.il Garbage In, Gospel Out
On 12-04-04 4:52 PM, Sam Steingold wrote:> Since R has the same namespace for functions and variables, >> c<- 1 > kills the global function, which can be restored by >> c<- get("c",mode="function") > > Is there a way to prevent R from overriding globals > or at least warning when I do that > or at least warning when I replace a functional value with non-functional?It doesn't kill it, it just hides it. You can still get the original by telling R which one you want, e.g. base::c. You'll get a warning when you do this in a package, e.g. library(Hmisc) will tell you that it has hidden 5 functions from view. There's no warning when you mask a function with a non-function at top level, and little need for one, because R does the right search based on the fact that you're making a function call: > c [1] 1 > c(1,2) [1] 1 2 It only matters when you need to pass the function as an argument, e.g. to one of the apply() family of functions. Duncan Murdoch
To expand on Duncan's answer, you haven't replaced it. The following should make that clear: ## starting in a fresh session> cfunction (..., recursive = FALSE) .Primitive("c")> find('c')[1] "package:base"> c <- 1 > find('c')[1] ".GlobalEnv" "package:base"> c[1] 1> rm(c) > find('c')[1] "package:base"> cfunction (..., recursive = FALSE) .Primitive("c") The one provided by R, and the one you created, are not in the same namespace. To "recover" R's version, get rid of the one you created.Also, take a look at the search() and conflicts() functions. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 4/4/12 1:52 PM, "Sam Steingold" <sds at gnu.org> wrote:>Since R has the same namespace for functions and variables, >> c <- 1 >kills the global function, which can be restored by >> c <- get("c",mode="function") > >Is there a way to prevent R from overriding globals >or at least warning when I do that >or at least warning when I replace a functional value with non-functional? > >thanks. > >-- >Sam Steingold (sds.podval.org) on Ubuntu 11.10 (oneiric) X >11.0.11004000 >childpsy.net iris.org.il camera.org >ffii.org >dhimmi.com mideasttruth.com pmw.org.il >Garbage In, Gospel Out > >______________________________________________ >R-help at r-project.org mailing list >stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.