[Rd] Reordering the search path?

Henrik Bengtsson hb at stat.berkeley.edu
Wed Mar 7 01:39:12 CET 2007


Hi, without arguing for doing it or not, is the following a correct
way to reorder the search path:

moveInSearchPath <- function(from, to) {
  # Excluding validation of 'from' and 'to' here etc.

  # Get enviroment to be moved
  env <- pos.to.env(from);

  # Detach old position without side effects, cf. detach().
  .Internal(detach(from));

  if (to > from)
    to <- to - 1;

  # Attach at new position
  attach(env, pos=to, name=attr(env, "name"));
}

Thanks

/Henrik



More information about the R-devel mailing list