.GlobalEnv <- globalenv()
attach(NULL, name = "Autoloads")
.Autoloaded<-NULL
.AutoloadEnv <- pos.to.env(2)
T <- TRUE
F <- FALSE
version <- Version()
.Machine <- Machine()
options(na.action = "na.omit")
.Library <- paste(getenv("RHOME"), "library", sep = "\\")
.lib.loc <- unique(c(unlist(strsplit(getenv("RLIBS"), ":")), 
.Library))
options(papersize = "a4")
.First <- function() windows()

system.file<-function (file = "", pkg = .packages(), lib = .lib.loc) 
{
        FILES <- paste(t(outer(lib, pkg, paste, sep = "/")), 
                file, sep = "/", collapse = " ")
	ff <- strsplit(FILES, " ")
        .Internal(system.file(ff[[1]]))
}

library <-
function (name, help, lib.loc = .lib.loc, character.only = FALSE,
	  logical.return = FALSE)
{
  if (!missing(name)) {
    if (!character.only)
      name <- as.character(substitute(name))
    lib.source <- function(file, env) {
      exprs <- parse(n = -1, file = file)
      if (length(exprs) == 0)
	return(invisible())
      for (i in exprs) yy <- eval(i, env)
      invisible()
    }
    pkgname <- paste("package", name, sep = ":")
    if (is.na(match(pkgname, search()))) {
      packagedir<-system.file("",name,lib.loc)
      which.lib.loc<-lib.loc[match(packagedir,paste(lib.loc,name,"",sep="/"))]
      if (packagedir == "") {
	txt <- paste("There is no package called `",
		     name, "'", sep = "")
	if (logical.return) {
	  warning(txt)
	  return(FALSE)
	}
	else stop(txt)
      }
      file <- system.file(paste("R", name, sep = "/"), name, lib.loc)
      env <- attach(NULL, name = pkgname)
      if (file == "")
	warning(paste("Package `", name, "' contains no R code", sep = ""))
      else
      lib.source(file, env)
      lib.fixup(env, .GlobalEnv)
      if (exists(".First.lib", envir = env, inherits = FALSE)) {
	firstlib <- get(".First.lib", envir = env, inherits = FALSE)
	firstlib(which.lib.loc, name)
      }
    }
  } else if (!missing(help)) {
    if (!character.only)
      help <- as.character(substitute(help))
    file <- system.file("INDEX", help, lib.loc)
    if (file == "")
      stop(paste("No documentation for package `",
		 help, "'", sep = ""))
    else
      wincat(file)

  } else
    for (lib in lib.loc) {
      cat(paste(ifelse(first, "", "\n"), "Packages in library `",
		lib, "':\n\n", sep = ""), file = file,
	  append = TRUE)
      INDEX <- paste(lib, "LibIndex", sep = "/")
      wincat( INDEX)
    }
  if (logical.return)
    TRUE
  else invisible(.packages())
}

library.dynam <-
function(chname, package = .packages(), lib.loc = .lib.loc) {
  if (!exists(".Dyn.libs"))
    assign(".Dyn.libs", character(0), envir = .AutoloadEnv)
  if(missing(chname) || (LEN <- nchar(chname)) == 0)
    return(.Dyn.libs)
  if (substr(chname, LEN - 2, LEN) == ".so") {
    chname <- substr(chname, 1, LEN - 3)
  }
  if (is.na(match(chname, .Dyn.libs))) {
    file <- system.file(paste("libs", "/", chname, ".", "dll", sep = ""),
			package, lib.loc)
    if (file == "") {
      stop(paste("dynamic library `", chname, "' not found", sep = ""))
    }
    .Internal(dyn.load(file))
    assign(".Dyn.libs", c(.Dyn.libs, chname), envir = .AutoloadEnv)
  }
  invisible(.Dyn.libs)
}

coef.lm<-function(z) z$coefficients
fitted.lm<-function(z) z$fitted.values

data <- function(..., list = character(0), package =c(.packages(),.Autoloaded),
		 lib.loc = .lib.loc) {
 names <- c(as.character(substitute(list(...))[-1]), list)
 if (!missing(package))
	if (is.name(y <- substitute(package)))
		package <- as.character(y)
 found <- FALSE
 if (length(names) == 0) { #-- give 'index' of all possible data sets
	for (lib in lib.loc)
	  for (pkg in package) {
		INDEX <- system.file(paste("data", "index.doc", sep = "/"),
				     pkg, lib)
		if (INDEX != "") {
		  cat(paste(ifelse(found, "\n", ""),
			    "Data sets in package `", pkg, "':\n\n", sep = ""))
		  wincat(INDEX)
                  if(!found) found <- TRUE
		}
	}
 }
 else for (name in names) {
	dn <- paste("data/", name, sep="")
	files <- system.file(paste(dn, ".*",sep=""), package, lib.loc)
	if (length(files)>1 || files != "") { #-- found >= 1
          for(file in files) {
                nc <- nchar(file)
                if((ext <- substr(file,nc-1,nc))== ".R" || ext== ".r") {
                  found <- TRUE; source(file)
                } else if(substr(file,nc-3,nc) == ".tab") {
                  found <- TRUE
                  assign(name, read.table(file, header=TRUE), env = .GlobalEnv)
                }
          }
        }
 }
 if(!found)
        stop("No data sets found")
 invisible(names)
}

wincat<-function(ifile, ofile="", append = TRUE)
  .Internal(wincat(ifile,ofile,append))

datadirs<-function() system.file("data")

help.start<-function(gui="irrelevant",browser="netscape",remote=NULL)
	{
	#the arguments are ignored in windows
	.Internal(help.start(gui,browser,remote))
}
