# function SHORT. # last mod: 22 June 08 #to display part of a vector #or some subset of a matrix -- R coerces tensor into vector for you. # # things to do: as at work, add a 'skip' value to display data # offset from ends. Now, there's window() which, if called as # window(as.vector(x)) may be useful -OTOH it returns a timeseries # which is not really what I want short <- function(x=seq(1,20),numel=4,ynamey=deparse(substitute(x))) { ynam<-as.character(ynamey) #clean up spaces ynam<-gsub(" ","",ynam) # I can't recall what I was worried about. ynam is just fine #if(length(ynam)>1) #some idiot entered a value #{ # stop("Usage:short(name [,number_of_elements_to_show]) \n") #} if(2*numel >= length(x)) { print(x) } else { cat(paste(ynam,'[1] thru ',ynam,'[',numel,']\n',sep="")) print(x[1:numel]) cat(' ... \n') #need to print values of length(x)-number+1 or some such cat(paste(ynam,'[',length(x)-numel+1,'] thru ', ynam, '[', length(x),']\n',sep="")) print(x[(length(x)-numel+1):length(x)]) } }