# Functions for lab 9 # by Tom Minka # R 1.7.1 ############################################################################# # Standard startup if(!exists("zip.unpack")) { zip.unpack <- function(path,destdir) { cmd = paste("unzip -q",path,"-d",destdir) status = system(cmd) if(status > 0) stop(paste("unzip failed. do you have",path,"?")) status } } install.local <- function(package,path="",destdir=NULL,chdir=T) { if(is.null(destdir)) destdir = tempdir() if(path == "") { if(exists("choose.files")) path = choose.files(caption=paste("Select",package,"zip file"),multi=F) else path = "mining.zip" } zip.unpack(path,destdir) #package = basename(path) #package = strsplit(package,"_")[[1]][1] library(package,lib.loc=destdir,character.only=T,warn=F) if(chdir) { olddir = getwd() newdir = dirname(path) setwd(newdir) # get the canonical version of newdir newdir = getwd() if(newdir != olddir) { cat("Working directory is now",newdir,"\n") } } } my.require <- function(package) { package = deparse(substitute(package)) if(length(.find.package(package,quiet=T))>0) library(package,char=T) else install.local(package) } my.require(mining) ############################################################################# load("lab9.rda")