I sometimes find that a function I have defined has the same name as an R core function. In most cases I have no desire to redefine the core R function and would prefer to give my function a different name. The problem is that R lets users redefine its core functions without any warning. Is there a way to cause R to generate a warning if a core function is being redefined? To give an actual example, in my personal library of functions I have a 'seek' function. I recently noticed that seek(con, ...) is part of base R. Now I plan to rename my personal 'seek' function but would have benefited from a warning when I first created this function. [[alternative HTML version deleted]]
On 13-08-03 3:47 AM, Rguy wrote:> I sometimes find that a function I have defined has the same name as an R > core function. In most cases I have no desire to redefine the core R > function and would prefer to give my function a different name. > > The problem is that R lets users redefine its core functions without any > warning. Is there a way to cause R to generate a warning if a core function > is being redefined? > > To give an actual example, in my personal library of functions I have a > 'seek' function. I recently noticed that seek(con, ...) is part of base R. > Now I plan to rename my personal 'seek' function but would have benefited > from a warning when I first created this function.You haven't redefined the core function, you have created a new function that masks it. The original is still available. The solution is to keep your personal library of functions small so masking is obvious or not a problem, or to put it into a package. If you put your personal library into a package, you'll be warned if your package masks a base function. Duncan Murdoch
One could get in the habit of typing conflicts() from time to time. Or perhaps conflicts(,TRUE)$.GlobalEnv Various ways of semi-automating this come to mind, such as putting it in one's .Rprofile file. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/3/13 12:47 AM, "Rguy" <rguy at 123mail.org> wrote:>I sometimes find that a function I have defined has the same name as an R >core function. In most cases I have no desire to redefine the core R >function and would prefer to give my function a different name. > >The problem is that R lets users redefine its core functions without any >warning. Is there a way to cause R to generate a warning if a core >function >is being redefined? > >To give an actual example, in my personal library of functions I have a >'seek' function. I recently noticed that seek(con, ...) is part of base R. >Now I plan to rename my personal 'seek' function but would have benefited >from a warning when I first created this function. > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.