On 10/11/12 12:08, Martin J Reed wrote:
Rolf and Duncan

Many thanks. Your answers pointed me to a refinement that is closer to what I 
want:

   rm(list=intersect(ls(".GlobalEnv"),ls("package:reedgraph")),
      pos=".GlobalEnv")

This only removes items that are "masked" by GlobalEnv from my package.

As this is a bit long for some of the people that need to update their 
workspaces I have created a function to fix it:

<packagename>.update2package  <- function() {
   rm(list=intersect(ls(".GlobalEnv"),ls("package:<packagename>")),
      pos=".GlobalEnv")
}

Just for completeness (if anyone else reads this). It is possible to make this 
happen automatically at package load using

.onAttach <- function(libname, pkgname) { <packagename>.update2package() }

However, as Duncan says this is REALLY bad practice, but is useful to me while 
debugging….

I really don't see it as being at all useful. What is the point, in terms of package development, of keeping copies of those functions in the global environment if
you are going to remove them whenever you load the package?

It sounds to me like you need to implement some system of version control,
such as subversion (svn). Personally I use rcs --- simple enough for the simple
minded such as my very good self to use, and amply adequate for my needs.

A version control system allows you to "backtrack" if a revision that you make
to a bit of software turns out to be undesirable.  It will do that much more
effectively IMHO than your current shaganappi strategy.

Finally you should note that CRAN policies expressly forbid the sort of thing that you propose doing with your .onAttach() function, should you ever be inclined to submit
your package to CRAN.

    cheers,

        Rolf

______________________________________________
R-help@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.

Reply via email to