prettyR/0000755000176200001440000000000013453024453011726 5ustar liggesusersprettyR/NAMESPACE0000644000176200001440000000121412710102643013134 0ustar liggesusers# created 6/9/2011 - Jim Lemon, importFrom("grDevices", "bmp", "graphics.off", "jpeg", "png") importFrom("stats", "as.formula", "chisq.test", "terms") importFrom("utils", "browseURL") export( add.value.labels, AddNav, AddNavItem, addxtabs, BeginNav, brkdn, calculate.xtab, CreateIndexFile, createIndxFile, decimal.align, delim.table, delim.xtab, describe, describe.factor, describe.logical, describe.numeric, EndHTML, freq, HTMLgraph, htmlize, Mode, R2html, rep_n_stack, skew, StartList, StartNav, stretch_df, toNA, truncString, valid.n, xtab ) # methods S3method(print,freq) S3method(print,xtab) S3method(print,desc) prettyR/NEWS0000755000176200001440000000445713444565665012461 0ustar liggesusersversion 2.2-3 added significance specification in delim.table version 2.2-1 fixed column spacing in print.xtab version 2.2 added imports for R CMD check version 2.1-1 changed all instances of nchar() to nzchar() version 2.1 added a print method for the "describe" function version 2.0-9 rewrite of the "describe" family version 2.0-8 Add TIFF device to htmlize version 2.0-7 Rebuild for R-3.0 version 2.0-6 nothing really version 2.0-5 added the ability to stack a matrix of values to rep_n_stack fixed the bug in describe.logical when all values were either TRUE or FALSE version 2.0-4 fixed the freq function that I totally screwed up in 2.0-2 version 2.0-3 removed the deprecated mean(data.frame) call by coercing to matrix finally fixed the value name spacing in describe.factor version 2.0-2 made decreasing order in freq optional version 2.0-1 fixed the right alignment in the decimal.align function reformatted the non-HTML tables in print.xtab new skew function and, of course, it now has a NAMESPACE version 2.0 added optional HTML formatting to the xtab function added sorting to the freq function added the rep_n_stack function to reshape data frames version 1.9-1 increased the default spacing for variable names to 20 in describe version 1.9 finally fixed the spacing in the column names in print.xtab version 1.8-9 I think I've finally fixed the justification in truncString version 1.8-8 added the fname.space argument to the describe function version 1.8-7 added truncation for long column labels in print.xtab added the addxtabs function version 1.8-6 fixed the formatting bug in print.xtab that I introduced in version 1.8-5 added the skew function version 1.8-5 More rewriting of the describe family added the truncString function version 1.8-4 rewriting of the describe family for better formatting version 1.8-3 added vertical list output in the describe functions version 1.8-1 removed _all_ the \samp tags version 1.8 rewrote xtab to return a nested list when more than one table is generated. removed \samp tags from \link tags version 1.7 added the or (odds ratio) argument to the xtab and print.xtab functions and the automatic display of relative risk. fixed the integer overflow in print.xtab (thanks to Harold Baize). prettyR/R/0000755000176200001440000000000013452522116012125 5ustar liggesusersprettyR/R/addxtabs.R0000755000176200001440000000160213350653216014047 0ustar liggesusersaddxtabs<-function(x) { if(!is.list(x) || class(x[[1]]) != "xtab") stop("addxtabs adds a list of xtab results with equal numbers of columns") allrownames<-unlist(lapply(lapply(x,"[[","counts"),rownames)) rowlabels<-sort(unique(allrownames)) allcolnames<-unlist(lapply(lapply(x,"[[","counts"),colnames)) collabels<-sort(unique(allcolnames)) dimx1<-dim(x[[1]]$counts) outmat<-matrix(0,nrow=length(rowlabels),ncol=dimx1[2]) for(xt in 1:length(x)) { currowlab<-rownames(x[[xt]]$counts) for(row in 1:length(currowlab)) { curcollab<-colnames(x[[xt]]$counts) whichrow<-rowlabels%in%currowlab[row] for(column in 1:length(curcollab)) { whichcol<-collabels%in%curcollab[column] outmat[whichrow,whichcol]<- outmat[whichrow,whichcol]+x[[xt]]$counts[row,column] } } } rownames(outmat)<-rowlabels colnames(outmat)<-collabels return(outmat) } prettyR/R/print.xtab.R0000755000176200001440000000753213452522116014353 0ustar liggesusersprint.xtab<-function (x,col.width=8,or=TRUE,chisq=TRUE,phi=TRUE, rowname.width=NA,html=FALSE,bgcol="lightgray",...) { tdim <- dim(x$counts) ncols<-tdim[2]+2 row.labels<-format(names(x$row.margin),width=col.width) if(is.na(rowname.width[1])) rowname.width<-ifelse(html,max(nzchar(row.labels),col.width),col.width) if(any(nzchar(row.labels) > rowname.width)) truncString(row.labels,ifelse(html,rowname.width,col.width)) rowname.space<-paste(rep(" ",rowname.width),sep="",collapse="") if(html) cat("\n\n
\n",sep="") cat("Crosstabulation of",x$varnames[1],"by",x$varnames[2],"\n") if(html) cat("
",sep="") else cat("\t") cat(x$varnames[2]) col.labels<-names(x$col.margin) if(max(nzchar(col.labels)) > col.width) col.labels<-truncString(col.labels,maxlen=col.width,justify="left") if(html) cat("
",x$varnames[1],sep="") else cat("\n",truncString(x$varnames[1],maxlen=rowname.width-1),"\t",sep="") for(i in 1:length(col.labels)) { if(html) cat("") cat("",truncString(col.labels[i],maxlen=col.width)) } cat("\n") gt <- sum(x$counts) for(i in 1:tdim[1]) { if(html) cat("
") cat(ifelse(html,row.labels[i],truncString(row.labels[i],maxlen=col.width))) if(html) { for(j in 1:tdim[2]) { if(html) cat("") cat(x$counts[i,j]) if(html) cat("
") cat(round(100*x$counts[i,j]/x$row.margin[i],2)) if(html) cat("
") cat(round(100*x$counts[i,j]/x$col.margin[j],2)) } if(html) cat("
") cat(x$row.margin[i]) if(html) cat("
-
") cat(round(100*x$row.margin[i]/gt,2),"\n") } else { cat(format(c(x$counts[i,],x$row.margin[i]),width=col.width,justify="right"), "\n",sep="") cat(rowname.space,format(c(round(100*x$counts[i,]/x$row.margin[i],2),"-"), width=col.width,justify="right"),"\n",sep="") cat(rowname.space,format(round(c(100*x$counts[i,]/x$col.margin, 100*x$row.margin[i]/gt),2),width=col.width),"\n\n",sep="") } } if(html) { cat("
\n") for(i in 1:tdim[2]) { if(html) cat("") cat(x$col.margin[i]) if(html) cat("
") cat(round(100*x$col.margin[i]/gt,2)) } cat("
",gt,"
100\n") } else { cat(rowname.space,format(c(x$col.margin,gt),width=col.width),"\n",sep="") cat(rowname.space, format(c(round(100*x$col.margin/gt,2),100),width=col.width),"\n",sep="") } if(chisq) { x2<-chisq.test(x$counts, ...) if(html) cat("
",sep="") cat("X2[",x2$parameter,"]=",round(x2$statistic,3),", p=", x2$p.value,"\n\n",sep = "") } if(tdim[1]==2 && tdim[2]==2) { logical.names<-function(x,names1=c("FALSE","0","N","NO"), names2=c("TRUE","1","Y","YES")) { for (nameindex in 1:length(names1)) if(toupper(x[1]) == names1[nameindex] && toupper(x[2]) == names2[nameindex]) return(TRUE) return(FALSE) } if(or) { if(html) cat("
",sep="") cat("odds ratio =", round(x$counts[1,1]*x$counts[2,2]/(x$counts[1, 2]*x$counts[2,1]),2),"\n") if(logical.names(names(x$col.margin))) { if(html) cat("
",sep="") cat("relative risk (",x$varnames[1],"-",names(x$row.margin)[2], ") = ",round((x$counts[2,2]/x$row.margin[2])/ (x$counts[1,2]/x$row.margin[1]),2),"\n",sep="") } if(phi) { num<-x$counts[1,1]*x$counts[2,2]-x$counts[1,2]*x$counts[2,1] denom<-sqrt(as.numeric(x$row.margin[1])* as.numeric(x$row.margin[2])*as.numeric(x$col.margin[1])* as.numeric(x$col.margin[2])) if(html) cat("
",sep="") cat("phi =",round(num/denom,3),"\n") } } else if(phi) cat("phi coefficient only valid for 2x2 table\n") } if(html) cat("
\n") } prettyR/R/freq.R0000755000176200001440000000215012710102643013201 0ustar liggesusersfreq<-function(x,variable.labels=NULL,display.na=TRUE,decr.order=TRUE) { if(missing(x)) stop("A vector, dataframe or matrix must be supplied") xdim<-dim(x) if(is.null(xdim)) { if(is.null(variable.labels)) variable.labels<-deparse(substitute(x)) x<-list(x) nfreq<-1 } else { nfreq<-xdim[2] if(is.matrix(x)) x<-as.data.frame(x) if(is.null(variable.labels)) variable.labels<-names(x) if(is.null(variable.labels)) variable.labels<-paste("V",1:xdim[2],sep="",collapse="") } freq.list<-rep(list(0),nfreq) for(i in 1:nfreq) { nna<-sum(is.na(x[[i]])) names(nna)<-"NA" freqs<-table(x[[i]]) if(decr.order) freqorder<-order(freqs,decreasing=TRUE) else freqorder<-1:length(freqs) vl<-attr(x[[i]],"value.labels") if(!is.null(vl) & length(vl)) { vlabels<-attr(x[[i]],"value.labels") if(length(names(freqs)) < length(vlabels)) vlabels<-vlabels[vlabels%in%names(freqs)] names(freqs)<-names(vlabels) } if(display.na) freqs<-c(freqs[freqorder],nna) else freqs<-freqs[freqorder] freq.list[[i]]<-freqs } names(freq.list)<-variable.labels class(freq.list)<-"freq" return(freq.list) } prettyR/R/truncString.R0000755000176200001440000000051312710102643014567 0ustar liggesuserstruncString<-function(x,maxlen=20,justify="left") { toolong<-nzchar(x) > maxlen maxwidth<-ifelse(toolong,maxlen-3,maxlen) chopx<-substr(x,1,maxwidth) lenx<-length(x) for(i in 1:length(x)) if(toolong[i]) chopx[i]<-paste(chopx[i],"...",sep="") return(formatC(chopx,width=maxlen,flag=ifelse(justify=="left","-"," "))) } prettyR/R/delim.xtab.R0000644000176200001440000000335412711637074014313 0ustar liggesusersdelim.xtab<-function(x,pct=c("row","column","cell"),coltot=TRUE, rowtot=TRUE,ndec=1,delim="\t",interdigitate=TRUE, label=deparse(substitute(x))) { xmat<-x$counts if(coltot) { xmat<-rbind(x$counts,x$col.margin) rownames(xmat)<-c(rownames(x$counts),"Total") } if(rowtot) { xmat<-cbind(xmat,c(x$row.margin,sum(x$row.margin))) colnames(xmat)<-c(colnames(x$counts),"Total") } if(!is.na(pct[1])) { xtotal<-sum(x$row.margin) dimx<-dim(xmat) if(pct[1] == "row") { xpctmat<- matrix(paste(round(100*x$counts/x$row.margin,ndec),"%", sep=""),nrow=dimx[1]-1) xpctmat<-rbind(xpctmat, paste(round(100*x$col.margin/xtotal,ndec),"%",sep="")) xpctmat<-cbind(xpctmat,rep("100%",dimx[1])) } if(pct[1] == "column") { xpctmat<- matrix(paste(round(t(t(100*x$counts)/x$col.margin),ndec),"%", sep=""),ncol=dimx[2]-1) xpctmat<-cbind(xpctmat, paste(round(100*x$row.margin/xtotal,ndec),"%",sep="")) xpctmat<-rbind(xpctmat,rep("100%",dimx[2])) } if(pct[1] == "cell") { xpctmat<- matrix(paste(round(100*x$counts/xtotal,ndec),"%",sep=""),ncol=dimx[2]-1) xpctmat<-rbind(xpctmat, paste(round(100*x$col.margin/xtotal,ndec),"%",sep="")) xpctmat<-cbind(xpctmat, paste(c(round(100*x$row.margin/xtotal,ndec),100),"%",sep="")) } colnames(xpctmat)<-colnames(xmat) rownames(xpctmat)<-rownames(xmat) if(interdigitate) { xpmat<-cbind(xmat[,1],xpctmat[,1]) for(xcol in 2:dimx[2]) xpmat<-cbind(xpmat,xmat[,xcol],xpctmat[,xcol]) xpctmat<-xpmat colnames(xpctmat)<- as.vector(matrix(c(colnames(xmat),rep("%",dimx[2])), nrow=2,byrow=TRUE)) } } delim.table(xmat,delim=delim,leading.delim=FALSE,label=label) if(!is.na(pct[1])) delim.table(xpctmat,delim=delim,leading.delim=FALSE,label=label) } prettyR/R/delim.table.R0000755000176200001440000000573613445345026014453 0ustar liggesusersdelim.table<-function(x,filename="",delim=",",tabegin="",bor="",eor="\n", tablend="",label=deparse(substitute(x)),header=NULL,trailer=NULL,html=FALSE, show.rownames=TRUE,leading.delim=FALSE,show.all=FALSE,nsignif=4, con,open.con=FALSE) { if(html) { if(delim == ",") delim="" if(tabegin == "") tabegin="\n" if(bor == "") bor="\n" if(tablend == "") tablend="
" if(eor == "\n") eor="
\n" if(is.null(header)) header="\n" if(is.null(trailer)) trailer="\n" } if(missing(con)) { if(nzchar(filename)) { con<-file(filename,"w") # only this invocation knows that it has to close con open.con<-TRUE } else con<-"" if(!is.null(header)) cat(header,"\n",file=con) } if(is.list(x) && !is.data.frame(x) && length(x) > 1) { # break it down into components if(!is.null(label)) cat(label,eor,file=con) # when recursively calling delim.table, make sure that it doesn't try to open # another connection or close the one that is open for(component in 1:length(x)) delim.table(x[[component]],filename="",delim=delim,tabegin=tabegin,bor=bor, eor=eor,tablend=tablend,label=names(x[component]),html=FALSE, show.rownames=show.rownames,leading.delim=leading.delim, show.all=show.all,con=con) } else { xdim<-dim(x) if(length(xdim) > 2) stop("delim.table can only process 2D tables") if(is.null(xdim)) { if(show.all) { cat(label,eor,file=con) if(is.vector(x)) { if(is.expression(x)) cat("Can't print expression",file=con) else { for(xindex in 1:length(x)) cat(ifelse(is.numeric(x[xindex]),signif(x[xindex],nsignif), x[xindex]),delim,sep="",file=con) } cat(eor,eor,file=con) } else { options(show.error.messages = FALSE) xchar<-try(as.character(x)) options(show.error.messages = TRUE) #if(class(xchar) != "try-error") cat(xchar,eor,file=con) } } } else { cat(label,"\n",tabegin,"\n",sep="",file=con) if(show.rownames) row.names<-rownames(x) else row.names<-NULL col.names<-names(x) if(is.null(col.names)) col.names<-colnames(x) if(!is.null(col.names)) { if(show.rownames && !is.null(row.names)) { if(leading.delim) cat(delim,file=con) cat(col.names,sep=delim,file=con) } cat(eor,file=con) } for(row in 1:xdim[1]) { if(nzchar(bor)) cat(bor,file=con) if(show.rownames && !is.null(row.names)) { if(leading.delim) cat(delim,file=con) cat(row.names[row],file=con) } nxp<-ifelse(is.na(xdim[2]),length(x),xdim[2]) for(col in 1:nxp) { nextx<-ifelse(is.na(xdim),x[col],x[row,col]) cat(delim,ifelse(is.numeric(nextx),signif(nextx,nsignif),nextx), sep="",file=con) } cat("\n",file=con) } cat(eor, file = con) } cat(tablend,ifelse(html,"",eor),file=con) } if(open.con) { if(!is.null(trailer)) cat(trailer,"\n",file=con) close(con) } } prettyR/R/brkdn.R0000755000176200001440000000575113350652330013362 0ustar liggesusersbrkdn<-function(formula,data,maxlevels=10,num.desc=c("mean","var","valid.n"), width=10,round.n=2) { if(!missing(data) && !missing(formula)) { bn<-as.character(attr(terms(formula),"variables")[-1]) nbn<-length(bn) cat("\nBreakdown of",bn[1],"by",bn[nbn],"\n") if(!is.numeric(data[[bn[1]]])) stop("\nVariable on left of formula must be numeric") if(nbn > 2) { by.factor<-as.factor(data[[bn[nbn]]]) factor.levels<-levels(by.factor) factor.labels<-attr(data[,bn[nbn]],"value.labels") if(!is.null(names(factor.labels))) { factor.levels<-factor.labels factor.labels<-names(factor.labels) } if(is.null(factor.labels)) factor.labels<-factor.levels nlevels<-length(factor.levels) if(nlevels > maxlevels) { nlevels<-maxlevels cat("Too many levels - only using first",maxlevels,"\n") } brkstats<-vector("list",nlevels) names(brkstats)<-factor.levels[1:nlevels] for(i in 1:nlevels) { currentdata<-subset(data,by.factor==factor.levels[i]) for(j in 1:dim(currentdata)[2]) attr(currentdata[,j],"value.labels")<-attr(data[,j],"value.labels") cat(paste("\nVariable ",bn[1],sep="",collapse=""),"for",bn[nbn],"- level",factor.labels[i],"\n\n") cat(formatC(num.desc,width=10),"\n",sep="") junk<-describe.numeric(as.matrix(currentdata[bn[1]]),num.desc=num.desc) cat(formatC(round(junk,round.n), width = 10), "\n", sep = "") next.formula<-as.formula(paste(paste(bn[1],"~"),paste(bn[2:(nbn-1)],collapse="+"))) brkstats[[i]]<-brkdn(next.formula,currentdata,maxlevels=maxlevels,num.desc=num.desc) class(brkstats[[i]])<-"dstat" } class(brkstats)<-"dstat" invisible(brkstats) } else { by.factor<-as.factor(data[[bn[2]]]) factor.levels<-levels(by.factor) factor.labels<-attr(data[,bn[2]],"value.labels") if(!is.null(names(factor.labels))) { factor.levels<-factor.labels factor.labels<-names(factor.labels) } if(is.null(factor.labels)) factor.labels<-factor.levels nlevels<-length(factor.levels) if(nlevels > maxlevels){ nlevels<-maxlevels cat("Too many levels - only using first",maxlevels,"\n") } gstats<-matrix(NA,ncol=nlevels,nrow=length(num.desc)) colnames(gstats)<-factor.labels[1:nlevels] rownames(gstats)<-num.desc if(is.numeric(data[[bn[1]]])) { round.ns<-rep(round.n,length(num.desc)) npos<-match("valid.n",num.desc) if(!is.na(npos)) round.ns[npos]<-0 vwidth<-max(nzchar(factor.labels)) cat(formatC("Level",width=vwidth)) cat(formatC(num.desc,width=width),"\n",sep="") for(i in 1:nlevels) { currentdata<-subset(data[[bn[1]]],by.factor==factor.levels[i]) if(length(currentdata)){ gstats[,i]<-describe.numeric(currentdata,num.desc=num.desc) cat(formatC(factor.labels[i],width=vwidth), formatC(round(gstats[,i],round.ns),width=width),"\n") } } class(gstats)<-"dstat" rnames<-rownames(gstats) } invisible(gstats) } } else cat("Usage: brkdn(formula,data,maxlevels=10,num.desc=c(\"mean\",\"var\",\"valid.n\"))\n") } prettyR/R/add.value.labels.R0000755000176200001440000000054212710102643015353 0ustar liggesusersadd.value.labels<-function(x,value.labels) { attr(x,"value.labels")<-sort(unique(x)) lenvallab<-length(attr(x,"value.labels")) if(length(value.labels) > lenvallab) { cat("More value labels than values, only the first",lenvallab,"will be used\n") value.labels<-value.labels[1:lenvallab] } names(attr(x,"value.labels"))<-value.labels return(x) } prettyR/R/skew.R0000755000176200001440000000060212710102643013215 0ustar liggesusers# calculates the skew of a distribution for a vector of observations # (not counts or densities) skew<-function(x) { # get rid of NAs, worry about the effects later x<-x[!is.na(x)] nx<-length(x) meanx<-mean(x) devx<-x-meanx sampskew<-(sum(devx^3)/nx)/(sum(devx^2)/nx)^1.5 popskew<-sampskew*sqrt(nx*(nx-1))/(nx-2) return(list(sample=sampskew,population=popskew)) } prettyR/R/R2html.R0000755000176200001440000001537712710102643013433 0ustar liggesusers.packageName <- "prettyR" createIndxFile <- function(HTMLfile, navfile, listfile, title = "R listing") { # Create a connection basecon <- file(HTMLfile, "w") # Create the file with framesets cat("\n \n", file = basecon) cat(" ", title, "\n \n", sep = "", file = basecon) cat(" \n", file = basecon) cat(" \n", file = basecon) cat(" \n", file = basecon) cat(" \n\n", file = basecon) close(basecon) } StartNav <- function(navcon, title = "R listing", bgcolor = "#dddddd") { # Beginning of the nav file cat("\n \n", sep = "", file = navcon) cat("

", title, "

\n", sep = "", file = navcon) } AddNav <- function(navcon, Rcommand, listname) { # Add an entry in the nav file if (nzchar(Rcommand) > 20) Rcommand <- paste(substring(Rcommand, 1, 18), "...", sep = "") nametag <- make.names(paste("ni", Rcommand, sep = "")) cat(" \n", sep = "", file = navcon) cat(" ", Rcommand, "\n
\n", sep = "", file = navcon) return(nametag) } HTMLgraph <- function(listfile, graphfile = NULL, type = "png", ...) { # Create a graphic device associated with graphfile # and add the corresponding entry in the listfile # Make sure to close all previously opened device(s) graphics.off() # Get the path from listfile (we put all figures in the same directory) HTMLdir <- dirname(listfile) # If graphfile == NULL or graphfile == "", compute fig[#] automatically if (is.null(graphfile) || graphfile == "") { # Got a name for the graphfile that is not used yet i <- 0 repeat({ i <- i + 1; graphfile <- file.path(HTMLdir, paste("fig", i, ".", type, sep = "")); if (!file.exists(graphfile)) break }) } else { # A name is provided for this graphfile # Make sure it is located in the same directory as HTMLfile graphfile <- file.path(HTMLdir, basename(graphfile)) # Try to guess the format of the file from its extension graphtype <- tolower(sub("^.*[.](.+)$", "\\1", graphfile)) if (graphtype != graphfile) type <- graphtype } # Create the graph device res <- switch(type, png = png(graphfile, ...), bmp = bmp(graphfile, ...), jpeg = jpeg(graphfile, ...), stop("'type' must be one of: 'png', 'bmp' or 'jpeg'")) # Create the corresponding entry in the listfile cat("\n", sep = "") } R2html <- function(Rfile, HTMLfile, echo = TRUE, split = FALSE, browse = TRUE, title = "R listing", bgcolor = "#dddddd", ...) { # Rfile must exist! if (!file.exists(Rfile)) stop("You must specify an existing 'Rfile'!") # Make sure that HTMLfile has .htm[l] extension if (length(grep("\\.[hH][tT][mM][lL]?$", HTMLfile)) == 0) stop("'HTMLfile' must be a filename with .htm[l] extension!") # Make sure one has the full path to HTMLfile if (basename(HTMLfile) == HTMLfile) HTMLfile <- file.path(getwd(), HTMLfile) # Create names and connections for nav and list files baseHTMLfile <- basename(HTMLfile) # Only the file name witrhout path HTMLdir <- dirname(HTMLfile) basenavfile <- sub("\\.[hH][tT][mM][lL]?", "_nav.html", baseHTMLfile) navfile <- file.path(HTMLdir, basenavfile) baselistfile <- sub("\\.[hH][tT][mM][lL]?", "_list.html", baseHTMLfile) listfile <- file.path(HTMLdir, baselistfile) # Create the file defining frames createIndxFile(HTMLfile, basenavfile, baselistfile, title) # Create the nav file navcon <- file(navfile, "w") StartNav(navcon, title = title, bgcolor = bgcolor) # Create the list file and redirect output and messages to it listcon <- file(listfile, "w") StartList(listcon, title = title, bgcolor = bgcolor) sink(listcon, append = TRUE, type = "output", split =split) sink(listcon, append = TRUE, type = "message", split =split) # Instructions to execute when we exit the function on.exit({ sink(NULL, type = "output"); sink(NULL, type = "message"); close(navcon); close(listcon) }) # Read the content of the R script file Rcon <- file(Rfile, "r") Rcommands <- readLines(Rcon) close(Rcon) # Make sure there is no opened graphic devices, or close them graphics.off() # Process commands one by one cmd <- "" for(i in 1:length(Rcommands)) { # Possibly paste successives lines of a multiline command cmd <- paste(cmd, Rcommands[i], sep = "") cmdcon <- textConnection(cmd) commexp <- try(parse(cmdcon), silent = TRUE) close(cmdcon) # Do we got an error? if (inherits(commexp, "try-error")) { # Is it an incomplete code line? if (length(grep("\n2:", commexp)) == 0) { # This is a syntax error # Add a tag in the navfile nametag <- AddNav(navcon, cmd, baselistfile) cat("\n", sep = "", file = listcon) # Do we echo the command? if(echo) { cat("
\n> ", file = listcon)
					cat(cmd, "\n", file = listcon)
					cat("
\n", file = listcon) } # Print the error message cat("
\n", file = listcon)
				cat(commexp, file = listcon)
				cat("
\n", file = listcon) cmd <- "" } } else if (is.expression(commexp)) { # This code appears syntactically correct # Add a tag in the navfile nametag <- AddNav(navcon, cmd, baselistfile) cat("\n", sep = "", file = listcon) # Look if there is a forbidden instruction in the code forbidden <- c("connection", "fifo", "file", "sink") dont <- FALSE for (i in 1:length(forbidden)) if (length(grep(forbidden[i], cmd)) > 0) { dont <- TRUE cmd <- paste("#", cmd, sep = "") break } if(echo) { cat("
\n> ", file = listcon)
				cat(cmd, "\n", file = listcon)
				cat("
\n", file = listcon) } # Do we need to create a new HTML graph? # We are looking for: # --FIG[:figurename]-- if (length(grep("#\\s*--FIG(:[^-]+)?--", cmd)) > 0) { # Create a new HTMLgraph # Get the name off the figure to create graphfile <- sub("^.*#\\s*--FIG:?([^-]+)?--.*$", "\\1", cmd) HTMLgraph(listfile, graphfile) # Create a new graph } # Execute the command if (!dont) { cat("
\n", file = listcon)
				## PhG: I suppose that you want to evaluate this in the global environment?
				eval(parse(text = cmd), envir = .GlobalEnv)
				cat("
\n", file = listcon) } cmd <- "" } } # Close all currently opened graph devices graphics.off() # Finalize files EndHTML(navcon) EndHTML(listcon) # Possibly if (browse) browseURL(paste("file://", HTMLfile, sep = "")) } prettyR/R/print.freq.R0000755000176200001440000000176512710102643014347 0ustar liggesusersprint.freq<-function(x,show.pc=TRUE,cum.pc=FALSE,show.total=FALSE,...) { nfreq<-length(x) variable.labels <- names(x) for(i in 1:nfreq) { categories<-names(x[[i]]) maxchar<-max(c(nzchar(categories),4)) cat("\nFrequencies for", variable.labels[i],"\n") cat(" ", formatC(ifelse(categories == "","Missing",categories), width=maxchar)) if(show.total) cat(formatC("Total",width=maxchar)) cat("\n") cat(" ", formatC(as.character(x[[i]]),width = maxchar)) if(show.total) cat(formatC(sum(x[[i]]),width=maxchar)) cat("\n") if(show.pc) { percentages<-round(100*x[[i]]/sum(x[[i]]),1) cat("% ",formatC(as.character(percentages),width=maxchar),"\n") if(cum.pc) cat("cum%",formatC(as.character(cumsum(percentages)),width=maxchar),"\n") if(any(names(x[[i]]) == "NA")) { xlen<-length(x[[i]]) nna<-x[[i]][xlen] percentages<-round(100*x[[i]][-xlen]/sum(x[[i]][-xlen]),1) cat("%!NA",formatC(as.character(percentages),width = maxchar),"\n") } } cat("\n") } } prettyR/R/decimal.align.R0000755000176200001440000000105312710102643014734 0ustar liggesusersdecimal.align<-function(x,dechar=".",nint=NA,ndec=NA,pad.left=TRUE) { splitchar<-paste("[",dechar,"]",sep="") splitlist<-strsplit(as.character(x),splitchar) ints<-unlist(lapply(splitlist,"[",1)) ints[is.na(ints)]<-"0" if(pad.left) { if(is.na(nint)) nint<-max(nzchar(ints)) ints<-sprintf(paste("%",nint,"s",sep=""),ints) } if(is.na(ndec)) ndec<-max(nzchar(unlist(lapply(splitlist,"[",2)))) decs<-unlist(lapply(splitlist,"[",2)) decs[is.na(decs)]<-"0" decs<-sprintf(paste("%-",ndec,"s",sep=""), decs) return(paste(ints,decs,sep=dechar)) } prettyR/R/htmlize.R0000755000176200001440000001313712710102643013727 0ustar liggesusersCreateIndexFile<-function(HTMLbase,HTMLdir,title="R listing") { basecon<-file(paste(HTMLdir,"/",HTMLbase,".html",sep="",collapse=""),"w") cat("",title,"\n",file=basecon) cat(" \n",file=basecon) cat(" \n",file=basecon) cat(" \n \n",file=basecon) close(basecon) } AddNavItem<-function(Rcommand,navcon,listname,navindex) { navitem<-ifelse(nzchar(Rcommand)>20, paste(paste(unlist(strsplit(Rcommand,""))[1:18],sep="",collapse=""), "...",sep="",collapse=""), Rcommand) nametag<-paste("ni",navindex,sep="",collapse="") cat(" \n", file=navcon,sep="") cat(" ",navitem,"
\n
\n",file=navcon,sep="") return(nametag) } BeginNav<-function(navcon,bgcolor="#dddddd") { cat("\n \n",file=navcon,sep="") } StartList<-function(listcon,title="R listing",bgcolor="#dddddd",useCSS=NULL) { cat("\n \n ",title," \n",file=listcon) if(!is.null(useCSS)) cat(" \n",sep="",file=listcon) cat(" \n",file=listcon) cat(" \n",file=listcon,sep="") cat("

",title,"

\n",file=listcon) } EndHTML<-function(con,ending=NULL) { if(!is.null(ending)) cat(ending,file=con) cat(" \n\n",file=con) } htmlize<-function(Rfile,HTMLbase,HTMLdir,title, bgcolor="#dddddd",echo=FALSE,do.nav=FALSE,useCSS=NULL,...) { if(missing(Rfile)) stop("Minimal usage: htmlize(Rfile,...)") # Is Rfile there? if (!file.exists(Rfile)) { stopstring<-paste("Can't find",Rfile,collapse="") stop(stopstring) } # read in the commands Rcon<-file(Rfile,"r") Rcommands<-readLines(Rcon) close(Rcon) # if there is no HTML base name, use the Rfile name if(missing(HTMLbase)) { HTMLbase<-unlist(strsplit(basename(Rfile),"\\.")) HTMLbase<-HTMLbase[1:(length(HTMLbase)-1)] } if(missing(title)) { if(charmatch("#title~",Rcommands[1],0)) title<-strsplit(Rcommands[1],"~")[[1]][2] else title<-paste("Listing of",HTMLbase) } # If there is no HTML directory, use the path on the Rfile if(missing(HTMLdir)) { if(length(grep("/",Rfile))) HTMLdir<-unlist(strsplit(Rfile,"/")) else HTMLdir<-unlist(strsplit(Rfile,"\\\\")) HTMLdir<- ifelse(length(HTMLdir)==1,".",file.path(HTMLdir[-length(HTMLdir)])) } if(do.nav) { CreateIndexFile(HTMLbase,HTMLdir,title) navcon<-file(paste(HTMLdir,"/",HTMLbase,"_nav.html",sep="",collapse=""),"w") BeginNav(navcon,bgcolor=bgcolor) #navname<-paste(HTMLbase,"_nav.html",sep="",collapse="") listname<-paste(HTMLdir,"/",HTMLbase,"_list.html",sep="",collapse="") } else { listname<-paste(HTMLdir,"/",HTMLbase,".html",sep="",collapse="") } listcon<-file(listname,"w") StartList(listcon,title=title,bgcolor=bgcolor,useCSS=useCSS) listname<-paste(HTMLbase,"_list.html",sep="",collapse="") sink(listcon) on.exit({ sink(NULL,type="output"); sink(NULL,type="message"); if(do.nav) close(navcon); close(listcon) }) forbidden <- c("connection","fifo","file","sink") GraphicDevices<-c("bitmap","bmp","jpeg","png","tiff") thiscommand<-"" navindex<-1 for(i in 1:length(Rcommands)) { if(echo) cat(Rcommands[i],"
\n",file=listcon) # check for a comment character commentpos<-grep("#",Rcommands[i],fixed=TRUE) # cut out the comment if(length(commentpos)) Rcommands[i]<-strsplit(Rcommands[i],"#")[[1]][1] commexp<-try(parse(text=Rcommands[i]),silent=TRUE) # if this line is a complete command and thiscommand is not if(is.expression(commexp) && nzchar(thiscommand) > 0) # add a semicolon in case we're in braces Rcommands[i]<-paste(Rcommands[i],";",sep="",collapse="") thiscommand<-paste(thiscommand,Rcommands[i],sep="",collapse="") commexp<-try(parse(text=thiscommand),silent=TRUE) # If try doesn't yield an expression, it must be an incomplete line if(is.expression(commexp)) { if(do.nav) { nametag<-AddNavItem(thiscommand,navcon,listname,navindex) cat("\n",file=listcon,sep="") } fname<-strsplit(thiscommand,"\\(")[[1]][1] dont<-fname %in% forbidden if(dont) thiscommand<-paste("#",thiscommand,sep="",collapse=" ") navindex<-navindex+1 # if the function is assigning its value, peel off the assignment if(!is.na(charmatch("<-",fname))) fname<-strsplit(fname,"-")[[1]][2] # does this command open a graphics device? if(fname %in% GraphicDevices) { hasquote<-"\"" %in% unlist(strsplit(thiscommand,"")) gclist<-unlist(strsplit(thiscommand,ifelse(hasquote,"[\"]","[(,)]"))) if(!hasquote) gclist[2]<-get(gclist[2]) cat("

\n",sep="") if(hasquote) thiscommand<-paste(gclist[1],"\"",HTMLdir,"/",gclist[2],"\"", paste(gclist[3:length(gclist)],sep="",collapse=""),sep="",collapse="") else thiscommand<-paste(gclist[1],"(\"",HTMLdir,"/",gclist[2],"\",", paste(gclist[3:length(gclist)],sep="",collapse=""),")",sep="",collapse="") } # If it's not forbidden, evaluate the command if(!dont) { cat("

\n",file=listcon)
    eval(parse(text=thiscommand))
    cat("
\n",file=listcon) } # Get ready for a new command thiscommand<-"" } } EndHTML(listcon) if(do.nav) EndHTML(navcon) } prettyR/R/xtab.R0000755000176200001440000000310613452521636013217 0ustar liggesusersxtab<-function(formula,data,varnames=NULL,or=TRUE,chisq=FALSE,phi=FALSE, html=FALSE,bgcol="lightgray",lastone=TRUE) { if(missing(formula)) stop("Usage: xtab(formula,data,varnames=NULL,or=TRUE,chisq=FALSE,phi=FALSE\n") ft<-as.character(attr(terms(formula),"variables")[-1]) nft<-length(ft) xtnames<-ft[1] if(nft>2) { xt<-list() # use the last variable name in the formula first by.factor<-as.factor(data[[ft[nft]]]) factor.levels<-levels(by.factor) factor.labels<-attr(data[,ft[nft]],"value.labels") if(is.null(factor.labels)) factor.labels<-factor.levels nlevels<-length(factor.levels) for(i in 1:nlevels) { currentdata<-subset(data,by.factor==factor.levels[i]) for(j in 1:dim(currentdata)[2]) attr(currentdata[,j],"value.labels")<-attr(data[,j],"value.labels") currentcount<-length(currentdata[[nft]]) totalcount<-length(data[[nft]]) # delete the last variable name rightside<-ifelse(nft>3,paste(ft[2:(nft-1)],sep="",collapse="+"),ft[2]) next.formula<-as.formula(paste(ft[1],rightside,sep="~",collapse="")) xt[[i]]<-xtab(next.formula,data=currentdata,varnames=varnames,chisq=chisq, phi=phi,html=html,bgcol=bgcol,lastone=FALSE) xtnames<-c(xtnames,paste0(ft[nft],"_",names(factor.labels)[i])) } } else { if(is.null(varnames)) varnames<-ft if(missing(data)) xt<-calculate.xtab(get(ft[1]),get(ft[2]),varnames=varnames) else xt<-calculate.xtab(data[,ft[1]],data[,ft[2]],varnames=varnames) } if(lastone) { if(length(xtnames) > 1) names(xt)<-xtnames[-1] else names(xt)<-c("counts","row.margin","col.margin","varnames") } return(xt) } prettyR/R/toNA.R0000755000176200001440000000026012710102643013105 0ustar liggesuserstoNA<-function(x,values=NA) { if(missing(x)) stop("Usage: toNA(x,values=NA)\n\twhere value is one or more values to be set to NA") x[x %in% values] <- NA return(x) }prettyR/R/rep_n_stack.R0000644000176200001440000000331112710102643014531 0ustar liggesusersrep_n_stack<-function(data,to.stack,stack.names=NULL) { datadim<-dim(data) stackdim<-dim(to.stack) if(is.null(dim(to.stack))) { stackdim<-c(1,length(to.stack)) to.stack<-matrix(to.stack,ncol=length(to.stack)) } # if column names are passed, convert them to indices if(is.character(to.stack)) to.stack<-matrix(which(names(data) %in% to.stack),nrow=stackdim[1], ncol=stackdim[2],byrow=TRUE) # get the indices of the columns to be replicated to.rep<-which(!(1:datadim[2] %in% to.stack)) nrep<-length(to.rep) # if any columns are to be replicated, # form the new data frame by replicating the first to.rep column if(nrep) { newDF<-data.frame(rep(data[,to.rep[1]],stackdim[2])) # if there is more than one to.rep column, add the rest if(nrep > 1) { for(repvar in 2:nrep) newDF[[repvar]]<-rep(data[[to.rep[repvar]]],stackdim[2]) } if(is.null(stackdim)) stackdim<-1 for(stackrow in 1:stackdim[1]) { newDF<-cbind(newDF,rep(names(data[,to.stack[stackrow,]]),each=datadim[1]), unlist(data[,to.stack[stackrow,]])) } if(is.null(stack.names)) stack.names<-paste(rep(c("group","value"),stackdim[1]), rep(1:stackdim[1],each=stackdim[1]),sep="") names(newDF)<-c(names(data[to.rep]),stack.names) } else { # if no columns are to be replicated, just string out the whole # data frame into one column, then add the column and row names if(is.data.frame(data)) { newDF<-data.frame(unlist(data)) newDF[[2]]<-rep(names(data),datadim[2]) } else { newDF<-data.frame(as.vector(data)) newDF[[2]]<-rep(colnames(data),datadim[2]) } newDF[[3]]<-rep(rownames(data),each=datadim[1]) if(!is.null(stack.names)) names(newDF)<-stack.names } rownames(newDF)<-NULL return(newDF) } prettyR/R/stretch_df.R0000644000176200001440000000331412710102643014371 0ustar liggesusersstretch_df<-function(x,idvar,to.stretch,ordervar=NA,include.ordervar=TRUE) { xdim <- dim(x) # make sure that the fields have names if(is.null(names(x))) names(x)<-paste("V",1:xdim[2],sep="") # get the names of the fields that are constant within cases if(is.na(ordervar)) nostretch<-names(x)[!(names(x) %in% to.stretch)] else nostretch<-names(x)[!(names(x) %in% c(to.stretch,ordervar))] nnostretch<-length(nostretch) # get the maximum number of records for any case maxstretch<-max(table(x[,idvar])) # get the indices of the unique IDs nsindx<-which(!duplicated(x[,idvar])) # get the actual IDs IDs<-x[nsindx,idvar] # start the new data frame with just the IDs newdf<-data.frame(IDs) # if there are other constant fields if(nnostretch > 1) { # add them to the new data frame for(newcol in 2:nnostretch) { newdf[,newcol]<-x[nsindx,nostretch[newcol]] } } start<-nnostretch if(include.ordervar && !is.na(ordervar)) to.stretch<-c(to.stretch,ordervar) nstretch<-length(to.stretch) for(stretchcol in 1:nstretch) { # beginning at the first field beyond the constant fields # add a column of NAs for(newcol in (start+1):(start+maxstretch)) newdf[[newcol]]<-NA # jump to the next stretched field start<-start+maxstretch } names(newdf)<-c(nostretch,paste(rep(to.stretch,each=maxstretch), rep(1:maxstretch,nstretch),sep="_")) for(idno in 1:length(IDs)) { rows<-which(x[,idvar] == IDs[idno]) nrows<-length(rows) start<-nnostretch for(stretchvar in 1:nstretch) { if(is.na(ordervar)) stretchorder<-1:nrows else stretchorder<-order(x[rows,ordervar]) newdf[idno,(start+1):(start+nrows)]<- x[rows,to.stretch[stretchvar]][stretchorder] start<-start+maxstretch } } return(newdf) } prettyR/R/describe.R0000755000176200001440000000751613346162353014051 0ustar liggesusersMode<-function(x,na.rm=FALSE) { xtab<-table(x,useNA=ifelse(na.rm,"no","ifany")) xmode<-names(which(xtab == max(xtab))) if(length(xmode) > 1) xmode<-">1 mode" return(xmode) } valid.n<-function(x,na.rm=TRUE) { return(ifelse(na.rm,sum(!is.na(x)),length(x))) } describe.numeric<-function(x,varname="", num.desc=c("mean","median","var","sd","valid.n")) { desclen<-length(num.desc) desc.vector<-rep(0,desclen) if(nzchar(varname) == 0) varname<-deparse(substitute(x)) for(i in 1:desclen) { if(valid.n(x)) desc.vector[i]<-do.call(num.desc[i],list(x,na.rm=TRUE)) else desc.vector[i]<-NA } names(desc.vector)<-num.desc return(desc.vector) } describe.factor<-function(x,varname="",horizontal=FALSE, decr.order=TRUE) { if(nzchar(varname) == 0) varname<-deparse(substitute(x)) lenx<-length(x) factab<-table(x,useNA="ifany") factab<-rbind(factab,100*factab/sum(factab)) dimnames(factab)[[1]]<-c("Count","Percent") names(dimnames(factab))<-c(varname,"") if(decr.order) factab<-factab[,order(factab[1,],decreasing=TRUE)] return(factab) } describe.logical<-function (x, varname = "") { if (nzchar(varname) == 0) varname <- deparse(substitute(x)) cat(varname, "\n") nmiss <- sum(is.na(x)) if (all(is.na(x))) logjam <- c(0, 0) else logjam <- table(x, useNA = "ifany") logjam <- rbind(logjam, 100 * logjam/sum(logjam)) dimnames(logjam)[[1]] <- c("Count", "Percent") return(logjam) } describe<-function(x,num.desc=c("mean","median","var","sd","valid.n"), xname=NA,horizontal=FALSE) { if(missing(x)) stop("Usage: describe(x,...)\n\twhere x is a vector, data frame or matrix") if(!is.data.frame(x)) x<-as.data.frame(x) varnames<-names(x) if(is.null(varnames)) varnames<-paste("V",1:dim(x)[2],sep="") if(is.data.frame(x)) { if(is.na(xname)) xname<-deparse(substitute(x)) cat("Description of",xname,"\n") num.index<-which(sapply(x,is.numeric)) nnum<-length(num.index) num.result<-list() if(nnum) { for(numres in 1:nnum) num.result[[numres]]<- describe.numeric(x[[num.index[numres]]],num.desc=num.desc, varname=varnames[num.index[numres]]) names(num.result)<-varnames[num.index] } fac.index<-c(which(sapply(x,is.factor)),which(sapply(x,is.character))) nfac<-length(fac.index) fac.result<-list() if(nfac) { for(facres in 1:nfac) fac.result[[facres]]<-describe.factor(x[[fac.index[facres]]], varname=varnames[fac.index[facres]],horizontal=horizontal) names(fac.result)<-varnames[fac.index] } log.index<-which(sapply(x,is.logical)) nlog<-length(log.index) log.result<-list() if(nlog) { for(logres in 1:nlog) log.result[[logres]]<-describe.logical(x[[log.index[logres]]], varname=varnames[log.index[logres]]) names(log.result)<-varnames[log.index] } desc.list<-list(Numeric=num.result,Factor=fac.result,Logical=log.result) class(desc.list)<-"desc" return(desc.list) } else cat("describe: x must be a vector, matrix or data frame\n") } print.desc<-function(x,ndec=2,...) { desclen<-length(x) descnames<-names(x) for(desctype in 1:desclen) { typelen<-length(x[[desctype]]) if(typelen) { cat("\n",descnames[desctype],"\n") nvar<-length(x[[desctype]]) if(descnames[desctype] == "Numeric") { nrows<-length(x[[desctype]]) ncols<-length(x[[desctype]][[1]]) xmat<-matrix(round(unlist(x[[desctype]]),ndec), nrow=nrows,ncol=ncols,byrow=TRUE) colnames(xmat)<-names(x[[desctype]][[1]]) rownames(xmat)<-names(x[[desctype]]) print(xmat) } else { for(descvar in 1:nvar) { print(round(x[[desctype]][[descvar]],2)) xmax<-max(x[[desctype]][[descvar]][1,]) nmax<-sum(x[[desctype]][[descvar]][1,]==xmax) cat("Mode",ifelse(nmax > 1,">1 mode", names(which.max(x[[desctype]][[descvar]][1,]))),"\n") } } } } } prettyR/R/calculate.xtab.R0000755000176200001440000000166612711310712015150 0ustar liggesuserscalculate.xtab<-function(v1,v2,varnames=NULL) { counts<-table(v1,v2) row.margin<-apply(counts,1,sum) col.margin<-apply(counts,2,sum) vl1<-attr(v1,"value.labels") if(!is.null(vl1) && length(vl1)) { vl1<-sort(vl1) if(length(rownames(counts)) < length(vl1)) vl1<-vl1[vl1 %in% rownames(counts)] if(is.null(names(vl1))) names(row.margin)<-vl1 else names(row.margin)<-names(vl1) } vl2<-attr(v2,"value.labels") if(!is.null(vl2) && length(vl2)) { vl2<-sort(vl2) if(length(colnames(counts)) < length(vl2)) vl2 <- vl2[vl2 %in% colnames(counts)] if(is.null(names(vl2))) names(col.margin)<-vl2 else names(col.margin)<-names(vl2) } if(is.null(varnames)) { rowname<-deparse(substitute(v1)) colname<-deparse(substitute(v2)) } else { rowname<-varnames[1] colname<-varnames[2] } xt<-list(counts=counts,row.margin=row.margin,col.margin=col.margin, varnames=c(rowname,colname)) attr(xt, "class") <- "xtab" return(xt) } prettyR/MD50000644000176200001440000000534013453024453012240 0ustar liggesuserscf90b272639cb00cf453ee5265af3106 *DESCRIPTION 4344408c77dd5ab26de4f504e08487bc *NAMESPACE 02f78a9e991abd4ede435473fb414de7 *NEWS 32ec70553bfbe79d1d1a931cea6ccafd *R/R2html.R e04280ce32a17b8f0df869ffdae4b636 *R/add.value.labels.R fb1104a8134a23e199649001fe128075 *R/addxtabs.R 5605b7d179689d5c218760e0f961201e *R/brkdn.R e21b24ac20c2b9d69eba5beab50559b7 *R/calculate.xtab.R d753bc4be5d0c2586402ad3cd86ebf1d *R/decimal.align.R 723f54b7fde0e13913fcf2c1123199aa *R/delim.table.R 08e5ce6963310f356fce6486e599d6ff *R/delim.xtab.R 08d3c2c64b3a7732ca24badf0d6e01eb *R/describe.R bb025a2b2a2f270642b7a46ce7b96cc1 *R/freq.R d42a55305ac7414fffee112ec72eebf1 *R/htmlize.R 972db8990e05fb4dc0ef90d1d648344b *R/print.freq.R dbdf080f7e438be9d6156124f1fc227f *R/print.xtab.R c4e8ea81471c7ddf807a3d33683972e5 *R/rep_n_stack.R 55dc4ae197aeefb2ba18ebe85d4ea3d1 *R/skew.R 62c7080ff0c9e5a08fe9d97024e16736 *R/stretch_df.R da77e12b1ed1172d657d1a5c91e41aa6 *R/toNA.R dfe29e3c01b58c3ce7979082b5dd8dec *R/truncString.R cf6d07016002072013472687df1583cc *R/xtab.R 6991c23f85dc4f5567cdc7269b3632cf *man/AddNav.Rd 4a5bf0f437730b5e931eda4435c814fa *man/AddNavItem.Rd 707a955fdac7aa3d0994e0fda7a75143 *man/BeginNav.Rd 46cc0fd794ab5cf5906775bce5cb13bf *man/CreateIndexFile.Rd 630333d01810fca12115011fd050a135 *man/EndHTML.Rd 3266f04a54fe6bd754c7423f1c08643a *man/HTMLgraph.Rd bd5c85bc1fd57091c5d78baf9efc4637 *man/Mode.Rd e30e1fcfd6a98abfbf5a6aa36f9374be *man/R2html.Rd 15a70c9e7664ac0efe3a69d75f73ef63 *man/StartList.Rd 3937b6579e3035f8f5cae79983b96921 *man/StartNav.Rd b4391b88033910b8dc91441486c2aed2 *man/add.value.labels.Rd 012bd38557d04264074be6cea709f8bc *man/addxtabs.Rd be0491be90573f659d8e0ace1fdf608b *man/brkdn.Rd ed09c73cc25de82cfb37057eb12f1e46 *man/calculate.xtab.Rd 7687d2ed4893bb6e75ceac4f514368b4 *man/createIndxFile.Rd e7422f8a6258bde0f4ce57b6c2eecfdc *man/decimal.align.Rd f77675c38de1943dd0bd88a953d8405a *man/delim.table.Rd c9ef499b48c2e434efcf63588a7631b5 *man/delim.xtab.Rd 22bb858b35357e3aceee088a0a23800e *man/describe.Rd 062633757f940fedb4e74bfab4027b74 *man/describe.factor.Rd 8bf11770db5eb483cc2e2a6c2c880b00 *man/describe.logical.Rd f43f83bc4eb1507e2dc74620887e6c09 *man/describe.numeric.Rd 04b09279fbb6838ac74629e86b745077 *man/freq.Rd a91bd1314d5b79f697cb875603428153 *man/htmlize.Rd 2d944445e7fba3c6a2bc692ce9159fd3 *man/print.desc.Rd 2747c61b2b6b2f1a1f13ca0ef4691fa9 *man/print.freq.Rd eb32648a1ddb05594eb545ca0e9d3bdb *man/print.xtab.Rd 5a8a3227382a03f11942d32704065675 *man/rep_n_stack.Rd a59a6c86c117342872ca40cf02531a9e *man/skew.Rd 29a8d2d5a5692dd81378909f727c7d31 *man/stretch_df.Rd 28f5860c412bed50457f0e19640e3159 *man/toNA.Rd 31bfde7e849a6a11503c2ea3c037d969 *man/truncString.Rd fe2f7025e7eab7f8f49136537cfac8fd *man/valid.n.Rd 8a1f006328325d28f6933def32ff034e *man/xtab.Rd prettyR/DESCRIPTION0000755000176200001440000000100213453024453013430 0ustar liggesusersPackage: prettyR Version: 2.2-3 Title: Pretty Descriptive Stats Date: 2019-04-08 Author: Jim Lemon , Philippe Grosjean Maintainer: Jim Lemon Description: Functions for conventionally formatting descriptive stats, reshaping data frames and formatting R output as HTML. Imports: grDevices, stats, utils License: GPL (>= 2) NeedsCompilation: no Packaged: 2019-04-08 03:30:00 UTC; root Repository: CRAN Date/Publication: 2019-04-09 05:10:03 UTC prettyR/man/0000755000176200001440000000000013452540070012476 5ustar liggesusersprettyR/man/describe.numeric.Rd0000755000176200001440000000261212710102643016206 0ustar liggesusers\name{describe.numeric} \alias{describe.numeric} \title{ Description of numeric variables } \description{ Describes a numeric variable. } \usage{ describe.numeric(x,varname="", num.desc=c("mean","median","var","sd","valid.n")) } \arguments{ \item{x}{A numeric vector.} \item{varname}{The variable name to display.} \item{num.desc}{The names of the functions to apply to the vector.} } \details{ \samp{describe.numeric} displays the name of the vector and the results of the functions whose names are passed in \samp{num.desc}. Note that any functions that are called by \samp{describe.numeric} must have an \samp{na.rm} argument, even if it is a dummy. } \value{ The vector of values returned from the functions in \samp{num.desc}. } \author{Jim Lemon} \seealso{\link{describe}, \link{valid.n}} \examples{ x<-rnorm(100) # include a function that calculates the "smoothness" of a vector # of numbers by calculating the mean of the absolute difference # between each successive value - all values equal would be 0 smoothness<-function(x,na.rm=TRUE) { if(na.rm) x<-x[!is.na(x)] xspan<-diff(range(x)) return(mean(abs(diff(x))/xspan,na.rm=TRUE)) } describe(x,num.desc=c("mean","median","smoothness"),xname="x") # now sort the values to make the vector "smoother" describe(sort(x),num.desc=c("mean","median","smoothness"),xname="x") } \keyword{misc} prettyR/man/describe.Rd0000755000176200001440000000457112710102643014553 0ustar liggesusers\name{describe} \alias{describe} \title{Description of variables} \description{Describes a vector or the columns in a matrix or data frame.} \usage{ describe(x,num.desc=c("mean","median","var","sd","valid.n"),xname=NA, horizontal=FALSE) } \arguments{ \item{x}{A vector, matrix or data frame.} \item{num.desc}{The names of the functions to apply to numeric data.} \item{xname}{A name for the object \samp{x}, mostly where this would be a very long string describing its structure (e.g. if it was extracted by name from a data frame).} \item{horizontal}{Whether to display the results of \samp{describe.factor} across the page (TRUE) or down the page (FALSE).} } \details{ \samp{describe} displays a table of descriptive statistics for numeric, factor and logical variables in the object \samp{x}. The summary measures for numeric variables can easily be altered with the argument \samp{num.desc}. Pass a character vector with the names of the desired summary measures and these will be displayed at the top of the numeric block with their results beneath them. If quantiles are desired, the user will have to write wrapper functions that call \samp{quantile} with the appropriate type or probabilities and use the names of the wrapper functions in \samp{num.desc}. Remember that any function called by \samp{describe} must have an \samp{na.rm} argument. Percentages are now always displayed and returned in the tables for factor and logical variables. } \value{ A list with three components: \item{Numeric}{A list of the values returned from \samp{describe.numeric} for each column described.} \item{Factor}{A list of the tables for each column described.} \item{Logical}{A list of the tables for each column described.} } \author{Jim Lemon} \seealso{\link{Mode}, \link{valid.n}, \link{describe.numeric}, \link{describe.factor}} \examples{ sample.df<-data.frame(sex=sample(c("MALE","FEMALE"),100,TRUE), income=(rnorm(100)+2.5)*20000,suburb=factor(sample(1:4,100,TRUE))) # include the maximum values describe(sample.df,num.desc=c("mean","median","max","var","sd","valid.n")) # make up a function roughness<-function(x,na.rm=TRUE) { if(na.rm) x<-x[!is.na(x)] xspan<-diff(range(x)) return(mean(abs(diff(x))/xspan,na.rm=TRUE)) } # now use it describe(sample.df$income,num.desc="roughness",xname="income") } \keyword{misc} prettyR/man/describe.logical.Rd0000755000176200001440000000110512710102643016152 0ustar liggesusers\name{describe.logical} \alias{describe.logical} \title{ Description of logical variables } \description{ Describes a logical variable. } \usage{ describe.logical(x,varname="") } \arguments{ \item{x}{A logical.} \item{varname}{An optional name for the variable. \samp{describe} always passes the name of the variable.} } \details{ \samp{describe.logical} displays the name of the logical, a table of counts of its two values (TRUE, FALSE) and the percentage of TRUE values. } \value{nil} \author{Jim Lemon} \seealso{\link{table}} \keyword{misc} prettyR/man/AddNav.Rd0000755000176200001440000000136112710102643014122 0ustar liggesusers\name{AddNav} \alias{AddNav} \title{Add a navigation item (R2html).} \description{Add an item to the HTML navigation file.} \usage{AddNav(navcon,Rcommand,listname)} \arguments{ \item{navcon}{The connection for writing to the navigation file.} \item{Rcommand}{The current R command in the script file.} \item{listname}{The name of the listing file.} } \details{ \samp{AddNav} adds an entry to the navigation file, generates a name tag for that entry and returns it to be inserted into the listing file. If the \R{} command is longer than 20 characters, it is truncated to 18 characters and an ellipsis appended. } \value{ The name tag to link the listing to the navigation entry. } \author{Philippe Grosjean} \keyword{misc} prettyR/man/freq.Rd0000755000176200001440000000236712710102643013731 0ustar liggesusers\name{freq} \alias{freq} \title{Calculate a frequency table} \description{ Calculates one or more frequency table(s) from a vector, matrix or data frame. } \usage{ freq(x,variable.labels=NULL,display.na=TRUE,decr.order=TRUE) } \arguments{ \item{x}{a vector, matrix or data frame.} \item{variable.labels}{optional labels for the variables. The default is the name of the variable passed or the \samp{names} attribute if the variable has more than 1 dimension.} \item{display.na}{logical - whether to display counts of NAs.} \item{decr.order}{Whether to order each frequency table in decreasing order.} } \details{ \samp{freq} calls \samp{table} to get the frequency counts and builds a list with one or more components containing the value labels and counts. } \note{ The limit on the number of bins has been removed, so passing a numeric vector with many levels may produce a huge, useless "frequency" table. } \value{A list with one or more components. Each component includes the values of the relevant variable as the names.} \author{Jim Lemon} \seealso{\link{print.freq}} \examples{ A<-sample(1:10,130,TRUE) A[sample(1:130,6)]<-NA C<-sample(LETTERS[1:14],130,TRUE) C[sample(1:130,7)]<-NA test.df<-data.frame(A,C) freq(test.df) } \keyword{misc} prettyR/man/toNA.Rd0000755000176200001440000000104712710102643013627 0ustar liggesusers\name{toNA} \alias{toNA} \title{Set specified values in an object to NA} \description{Sets all specified values in an object to NA.} \usage{toNA(x,values=NA)} \arguments{ \item{x}{A vector, matrix or data frame (max 2D).} \item{values}{One or more values that are to be set to NA.} } \details{ \samp{toNA} sets all entries in an object in values to NA. Useful for converting various missing value samps to NA. } \value{The object with NAs replacing all specified values.} \author{Jim Lemon} \seealso{\link{\%in\%}} \keyword{misc} prettyR/man/skew.Rd0000755000176200001440000000072012710102643013734 0ustar liggesusers\name{skew} \alias{skew} \title{ Calculate the skew of a distribution. } \description{ Calculates the skew of a distribution using a simple formula. } \usage{ skew(x) } \arguments{ \item{x}{A vector of numeric values, supposedly drawn from a particular distribution.} } \details{ \samp{skew} calculates the asymmetry of the distribution of the values. } \value{The value calculated.} \author{Jim Lemon} \seealso{\link{sd}} \keyword{misc} prettyR/man/delim.xtab.Rd0000644000176200001440000000345312710102643015015 0ustar liggesusers\name{delim.xtab} \alias{delim.xtab} \title{Format a crosstabulation} \description{Format a 2D crosstabulation from xtab} \usage{ delim.xtab(x,pct=c("row","column","cell"),coltot=TRUE,rowtot=TRUE, ndec=1,delim="\t",interdigitate=TRUE,label=deparse(substitute(x))) } \arguments{ \item{x}{An object of class \samp{xtab}.} \item{pct}{Whether and how to calculate percentages.} \item{coltot,rowtot}{Whether to add the marginal totals.} \item{ndec}{The number of decimal places for percentages.} \item{delim}{The delimiter to use between columns. Defaults to TAB.} \item{interdigitate}{Whether to place each column of percentages next to its row of counts.} \item{label}{A label to be displayed before the table.} } \value{nil} \details{ \samp{delim.xtab} formats a crosstabulation in a manner similar to those produced by commercial spreadsheets, with a column of counts followed by a column of percentages. If \samp{interdigitate} is FALSE, the percentages will be displayed separately. \samp{delim.xtab} will only process one 2D xtab object at a time. To format only the counts, set \samp{pct} to NA. The intended use of \samp{delim.xtab} is producing tables that can be imported into most word processors. If a table is output to an HTML or text document formatted with TAB characters, the output can be copied and pasted into the word processor document and then converted to a table. } \author{Jim Lemon} \seealso{\link{xtab}} \examples{ alpha1<-sample(LETTERS[1:3],50,TRUE) alpha2<-sample(LETTERS[1:2],50,TRUE) alphas<-data.frame(alpha1,alpha2) alphatab<-xtab(alpha1~alpha2,alphas) delim.xtab(alphatab,pct="row",interdigitate=TRUE) delim.xtab(alphatab,pct="column",interdigitate=TRUE) delim.xtab(alphatab,pct="cell",interdigitate=TRUE) } \keyword{misc} prettyR/man/calculate.xtab.Rd0000755000176200001440000000140212710102643015653 0ustar liggesusers\name{calculate.xtab} \alias{calculate.xtab} \title{Calculate a crosstabulation} \description{Calculates the marginal totals and names for a crosstabulation.} \usage{ calculate.xtab(v1,v2,varnames=NULL) } \arguments{ \item{v1,v2}{The variables to be crosstabulated.} \item{varnames}{Labels for the variables (defaults to \samp{names(data))}} } \details{ \samp{calculate.xtab} calls \samp{table} for the base table, calculates the marginal totals and returns a list with these and the names of the variables that will be used by \samp{print.xtab}.} \value{ A list containing the value of \samp{table}, the row and column marginals and the names of the variables.} \author{Jim Lemon} \seealso{\link{table}, \link{print.xtab}} \keyword{misc} prettyR/man/createIndxFile.Rd0000755000176200001440000000153412710102643015655 0ustar liggesusers\name{createIndxFile} \alias{createIndxFile} \title{Write an index file for the current output (R2html).} \description{Write an index file for the current R2html output.} \usage{createIndxFile(HTMLfile,navfile,listfile,title="R listing")} \arguments{ \item{HTMLfile}{The file name for the HTML files.} \item{navfile}{The name for the HTML navigation frame file.} \item{listfile}{The name for the HTML listing file.} \item{title}{The title for the listing.} } \details{ \samp{createIndxFile} opens a new HTML index file. If there is another file with the same name, it will be overwritten. This is intentional, as the user may want to run \samp{R2html} repeatedly without generating multiple sets of files. It then writes the frameset definition into the file and closes it. } \value{nil} \author{Philippe Grosjean} \keyword{misc} prettyR/man/EndHTML.Rd0000755000176200001440000000066512710102643014166 0ustar liggesusers\name{EndHTML} \alias{EndHTML} \title{End an HTML file (htmlize).} \description{Append an ending to an HTML file.} \usage{EndHTML(con,ending=NULL)} \arguments{ \item{con}{The connection for writing to the HTML file.} \item{ending}{Any "trailer" information to be added to the file before closing it.} } \details{ \samp{EndHTML} appends a brief ending to an HTML file. } \value{nil} \author{Jim Lemon} \keyword{misc} prettyR/man/add.value.labels.Rd0000755000176200001440000000141012710102643016064 0ustar liggesusers\name{add.value.labels} \alias{add.value.labels} \title{Add value labels} \description{Adds value labels to a variable.} \usage{ add.value.labels(x,value.labels) } \arguments{ \item{x}{The variable to add the labels.} \item{value.labels}{The labels.} } \details{ \samp{add.value.labels} adds value labels like those from an SPSS .sav file. It makes it a bit easier to stick on value labels that have been lost or were not there in the first place.} \value{ The variable with the labels added.} \author{Jim Lemon} \examples{ fgh<-data.frame(sex=sample(1:2,20,TRUE),viviality=sample(1:3,20,TRUE)) fgh$sex<-add.value.labels(fgh$sex,c("Female","Male")) fgh$viviality<-add.value.labels(fgh$viviality,c("Alive","Dead","Zombie")) } \keyword{misc} prettyR/man/HTMLgraph.Rd0000755000176200001440000000162212710102643014553 0ustar liggesusers\name{HTMLgraph} \alias{HTMLgraph} \title{Create a graphic in HTML output (R2html).} \description{Creates a graphic file and links it to the HTML output.} \usage{HTMLgraph(listfile, graphfile = NULL,type = "png",...)} \arguments{ \item{listfile}{The name of the HTMLize listing file.} \item{graphfile}{The name for the graphic file (see Details).} \item{type}{The graphic format in which to write the image.} \item{...}{Additional arguments - currently ignored.} } \details{ \samp{HTMLgraph} sets up a graphic device to allow an R graphic to be written to a file and that file linked to the HTML listing. If no filename is passed, a name is constructed from \samp{fig} and a number that does not match any existing \samp{fignnn...} file. Only \samp{bmp, jpeg} and \samp{png} files are currently handled, defaulting to the last. } \value{nil} \author{Philippe Grosjean} \keyword{misc} prettyR/man/AddNavItem.Rd0000755000176200001440000000150012710102643014734 0ustar liggesusers\name{AddNavItem} \alias{AddNavItem} \title{Add a navigation item (htmlize).} \description{Add an item to the HTML navigation file.} \usage{AddNavItem(Rcommand,navcon,listname,navindex)} \arguments{ \item{Rcommand}{The current R command in the script file.} \item{navcon}{The connection for writing to the navigation file.} \item{listname}{The name of the listing file.} \item{navindex}{The number used to generate the name tag.} } \details{ \samp{AddNavItem} adds an entry to the navigation file, generates a name tag for that entry and returns it to be inserted into the listing file. If the \R{} command is longer than 20 characters, it is truncated to 18 characters and an ellipsis appended. } \value{ The name tag to link the listing to the navigation entry. } \author{Jim Lemon} \keyword{misc} prettyR/man/decimal.align.Rd0000755000176200001440000000266612710102643015465 0ustar liggesusers\name{decimal.align} \alias{decimal.align} \title{ Turn numbers into strings with aligned decimal points } \description{ Formats decimal numbers as strings with aligned decimal points. } \usage{ decimal.align(x,dechar=".",nint=NA,ndec=NA,pad.left=TRUE) } \arguments{ \item{x}{One or more decimal numbers.} \item{dechar}{The character used to separate the decimal part of a number.} \item{nint}{The number of characters to which the integer part of the numbers should be padded.} \item{ndec}{The number of characters to which the decimal part of the numbers should be padded.} \item{pad.left}{Whether the left (integer) side of the numbers should be padded as well as the right.} } \details{ \samp{decimal.align} splits the incoming numbers at the decimal point and pads the decimal part and optionally the integer part so that when the numbers are displayed in a monospaced font the decimal points will be aligned. Note that if an integer or a decimal part without an integer is passed, the function will insert a zero for the missing part. This is useful for displaying or storing aligned columns of decimal numbers when the user does not want to pad the decimal part with zeros as in the \samp{format} function. } \value{ The original numbers as strings, padded with spaces. } \author{Jim Lemon} \seealso{\link{sprintf}} \examples{ x<-c(1,2.3,44.55,666.777) decimal.align(x) } \keyword{misc} prettyR/man/describe.factor.Rd0000755000176200001440000000143112710102643016020 0ustar liggesusers\name{describe.factor} \alias{describe.factor} \title{ Description of factor variables } \description{ Describes a factor variable. } \usage{ describe.factor(x,varname="",horizontal=FALSE,decr.order=TRUE) } \arguments{ \item{x}{A factor.} \item{varname}{A name for the variable. \samp{describe} always passes the name.} \item{horizontal}{Whether to display the results across the page (TRUE) or down the page (FALSE).} \item{decr.order}{Whether to order the rows by decreasing frequency.} } \details{ \samp{describe.factor} displays the name of the factor, a table of its values, the modal value of the factor and the number of valid (not NA) values. } \value{nil} \author{Jim Lemon} \seealso{\link{Mode}, \link{valid.n}, \link{table}} \keyword{misc} prettyR/man/R2html.Rd0000755000176200001440000000656412710102643014147 0ustar liggesusers\name{R2html} \alias{R2html} \title{Read an R script and write HTML output} \description{Produces HTML output from an R script.} \usage{R2html(Rfile,HTMLfile,echo=TRUE,split=FALSE,browse=TRUE, title="R listing",bgcolor="#dddddd",...)} \arguments{ \item{Rfile}{The R script file from which to read the commands.} \item{HTMLfile}{The name for the HTML index file (see Details).} \item{echo}{Whether to include ("echo") the commands in the listing.} \item{split}{Whether to split the output (see \samp{\link{sink}})}. \item{browse}{Whether to automatically open the HTML output in the default browser when finished.} \item{title}{The title of the HTML page and the headings for the frames.} \item{bgcolor}{The background color for the frames.} \item{...}{Additional arguments - currently ignored.} } \details{ \samp{R2html} allows the user to produce an HTML listing from an existing R script. The script must already run correctly and, if there is any graphic output, contain the necessary comments at the end of each graphic command to set up the graphic devices. The graphic files will be linked to the HTML listing page so that they should be interleaved with text output and commands. Three files will be output. The first will be named \samp{HTMLfile} which must be a valid filename with the extension \samp{.html}. This file is the "index" file that sets up the HTML frameset. The second file will be named by concatenating \samp{HTMLfile} without its extension and \samp{_nav.html}. Its contents will be dispayed at the left side of the HTML output as a "navigation" list using the commands as names. The third file is named by concatentating \samp{HTMLfile} without its extension and \samp{_list.html}. This contains the program listing. All three files will be written in whatever directory is specified by the path to \samp{HTMLfile}. If this is missing, everything will be written in the current R directory. Commands that create or alter connections, such as \samp{sink} are "forbidden", not evaluated and marked as comments in the listing. This prevents such commands from altering the connections necessary to write the HTML files. To include graphic output in the HTML file, place a comment at the end of any function that produces a graphic like this \samp{#--FIG:filename.png--} and the appropriate graphic device is automatically set up. The filename may be left out, in which case a name will be generated. } \value{nil} \author{Philippe Grosjean} \examples{ rcon<-file("testR2html.R","w") cat("test.df<-data.frame(a=factor(sample(LETTERS[1:4],100,TRUE)),\n", file=rcon) cat(" b=sample(1:4,100,TRUE),c=rnorm(100),d=rnorm(100))\n",file=rcon) cat("describe(test.df)\n",file=rcon) cat("print(freq(test.df$a))\n",file=rcon) cat("xtab(a~b,test.df)\n",file=rcon) cat("brkdn(c~b,test.df)\n",file=rcon) cat("hist(test.df$b)#--FIG:hista.png--\n",file=rcon) cat("plot(test.df$c,test.df$d)#--FIG:plotcd.png--\n",file=rcon) close(rcon) # R2html("testR2html.R", "testR2html.html") # if you want to see the output, use the following line # system(paste(options("browser")," file:",getwd(),"/testR2html.html",sep="",collapse="")) # to clean up, use the following line # system("rm testR2html.R testR2html.html testR2html_nav.html") # system("rm testR2html_list.html hista.png plotcd.png") } \keyword{misc} prettyR/man/valid.n.Rd0000755000176200001440000000104612710102643014320 0ustar liggesusers\name{valid.n} \alias{valid.n} \title{ Find the number of valid (not NA) values } \description{ Finds the number of valid (not NA) or total values in an object. } \usage{ valid.n(x,na.rm=TRUE) } \arguments{ \item{x}{An object.} \item{na.rm}{Whether to count all values (FALSE) or only those not NA.} } \details{ \samp{valid.n} finds the number of valid values of the object if \samp{na.rm=TRUE}. } \value{The number of valid values or the length of the object.} \author{Jim Lemon} \seealso{\link{describe}} \keyword{misc} prettyR/man/StartList.Rd0000755000176200001440000000123512710102643014716 0ustar liggesusers\name{StartList} \alias{StartList} \title{Write the header for the HTML listing file (htmlize).} \description{Initiate the listing file for an R listing in HTML format.} \usage{StartList(listcon,title="R listing",bgcolor="#dddddd",useCSS=NULL)} \arguments{ \item{listcon}{The connection for writing to the listing file.} \item{title}{The title and heading for the listing frame.} \item{bgcolor}{The background color for the listing frame.} \item{useCSS}{Path and filename of a CSS stylesheet.} } \details{ \samp{StartList} sets up the file with the listing frame information for the HTML listing. } \value{nil} \author{Jim Lemon} \keyword{misc} prettyR/man/BeginNav.Rd0000755000176200001440000000106312710102643014455 0ustar liggesusers\name{BeginNav} \alias{BeginNav} \title{Write the header for the HTML navigation file (htmlize).} \description{Initiate the navigation file for an R listing in HTML format.} \usage{BeginNav(navcon,bgcolor="#dddddd")} \arguments{ \item{navcon}{The connection for writing to the navigation file.} \item{bgcolor}{The background color for the navigation frame.} } \details{ \samp{BeginNav} sets up the file with the navigation frame information for the HTML listing for the \samp{htmlize} function. } \value{nil} \author{Jim Lemon} \keyword{misc} prettyR/man/rep_n_stack.Rd0000644000176200001440000000453712710102643015262 0ustar liggesusers\name{rep_n_stack} \alias{rep_n_stack} \title{ Replicate and stack columns of a data frame } \description{ Reshape a data frame by stacking two or more columns into one and adding a factor, while replicating the remaining columns and stacking them to match the number of rows } \usage{ rep_n_stack(data,to.stack,stack.names=NULL) } \arguments{ \item{data}{A data frame.} \item{to.stack}{Which columns are to be stacked together (see Details).} \item{stack.names}{Names for the new factor and stacked column.} } \details{ \samp{rep_n_stack} takes two or more specified columns in a data frame and "stacks" them into a single column. It also creates a new factor composed of the replicated names of the columns that identifies from which column each value came. The remaining columns in the data frame are replicated to match the new number of rows. If \samp{to.stack} is a matrix of names or column numbers, \samp{rep_n_stack} will stack each row into two new columns, allowing multiple related sets of values to be stacked in one operation. A matrix or data frame of values can now be stacked so that the values can be displayed by a function like \samp{barNest} in the \pkg{plotrix} package. } \note{ \samp{rep_n_stack} only does what other reshaping functions can do, but may be more easy to understand. } \value{The reshaped data frame.} \author{Jim Lemon} \seealso{\link{reshape}} \examples{ wide.data<-data.frame(ID=1:10,Glup=sample(c("Montic","Subtic"),10,TRUE), Flimit1=runif(10,1,2),Flimit2=runif(10,1.5,2.5),Flimit3=runif(10,1.2,3), Glimit1=rnorm(10,mean=5),Glimit2=rnorm(10,mean=4),Glimit3=rnorm(10,mean=4.5)) # first just stack one set of related measures rep_n_stack(wide.data[,1:5],to.stack=c("Flimit1","Flimit2","Flimit3")) # now stack two sets of related measures and pass names for the stacks rep_n_stack(wide.data,to.stack=matrix(3:8,nrow=2,byrow=TRUE), stack.names=c("Limit_F","Value_F","Limit_G","Value_G")) # finally stack a matrix of means into a single column with the # row and column names becoming "factor" variables meanmat<-matrix(runif(16,10,20),nrow=4) rownames(meanmat)<-c("Plunderers","Storers","Refusers","Jokers") colnames(meanmat)<-c("Week1","Week2","Week3","Week4") rep_n_stack(meanmat,to.stack=1:4, stack.names=c("Returns","Occasion","Strategy")) } \keyword{misc} prettyR/man/Mode.Rd0000755000176200001440000000156412710102643013656 0ustar liggesusers\name{Mode} \alias{Mode} \title{ Find the modal value } \description{ Finds the modal value of an object (usually a factor). } \usage{ Mode(x,na.rm=FALSE) } \arguments{ \item{x}{An object, usually a factor.} \item{na.rm}{A dummy argument to make it compatible with calls to \samp{mean}, etc.} } \details{ \samp{Mode} finds the modal value of the object. If there are multiple modal values, it returns an appropriate message. If \samp{Mode} is called with a continuous variable, it will not in general return a sensible answer. It does not attempt to estimate the density of the values and return an approximate modal value. } \note{ This is not the same as \samp{mode} that determines the data mode of an object. } \value{The modal value of the object as a character string.} \author{Jim Lemon} \seealso{\link{describe}} \keyword{misc} prettyR/man/print.desc.Rd0000644000176200001440000000134712710102643015037 0ustar liggesusers\name{print.desc} \alias{print.desc} \title{Display descriptive stats output} \description{ Displays a list of descriptive statistics produced by \samp{describe}. } \usage{ \method{print}{desc}(x,ndec=2,...) } \arguments{ \item{x}{a list of descriptive statistics produced by \samp{describe}} \item{ndec}{The number of decimal places to display.} \item{...}{additional arguments passed to \samp{print}} } \details{ \samp{print.desc} displays the list of descriptive statistics produced by the \samp{describe} function. } \value{nil} \author{Jim Lemon} \seealso{\link{describe}} \examples{ test.df<-data.frame(A=c(sample(1:10,99,TRUE),NA),C=sample(LETTERS,100,TRUE)) test.desc<-describe(test.df) print(test.desc) } \keyword{misc} prettyR/man/truncString.Rd0000755000176200001440000000141012710102643015302 0ustar liggesusers\name{truncString} \alias{truncString} \title{ Truncate strings and add ellipses if a string is truncated. } \usage{ truncString(x,maxlen=20,justify="left") } \arguments{ \item{x}{A vector of strings.} \item{maxlen}{The maximum length of the returned strings.} \item{justify}{Justification for the new strings.} } \description{ Truncates one or more strings to a specified length, adding an ellipsis (...) to those strings that have been truncated. The justification of the strings can be controlled by the \samp{justify} argument as in \link{format}, which does the padding and justification. } \value{ The string(s) passed as \samp{x} now with a maximum length of \samp{maxlen}. } \author{Jim Lemon} \seealso{\link{substr}} \keyword{misc} prettyR/man/print.xtab.Rd0000755000176200001440000000352213452515324015067 0ustar liggesusers\name{print.xtab} \alias{print.xtab} \title{Display a 2D crosstabulation} \description{Displays a 2D crosstabulation with optional chi-squared test, odds ratio/relative risk and phi coefficient.} \usage{ \method{print}{xtab}(x,col.width=8,or=TRUE,chisq=TRUE,phi=TRUE, rowname.width=NA,html=FALSE,bgcol="lightgray",...) } \arguments{ \item{x}{The list returned by \samp{calculate.xtab}.} \item{col.width}{Width of the columns in the display.} \item{or}{whether to calculate the odds ratio and relative risk (only for 2x2 tables).} \item{chisq}{Whether to call \samp{chisq.test} and display the result.} \item{phi}{Whether to calculate and display the phi coefficient (only for 2x2 tables).} \item{rowname.width}{Optional width for the rownames. Mostly useful for truncating very long rownames.} \item{html}{Whether to format the table with HTML tags.} \item{bgcol}{Background color for the table.} \item{...}{additional arguments passed to \samp{chisq.test}.} } \details{ \samp{print.xtab} displays a crosstabulation in a fairly conventional style with row, column and marginal percentages. If \samp{html} is TRUE, the formatting will use HTML tags and will only be useful if viewed in an HTML browser. In order to get HTML formatting, save, the output of \samp{xtab} and print with the argument \samp{html=TRUE}. If \samp{or} is \samp{TRUE} and the resulting table is 2x2, the odds ratio will be displayed below the table. If the function \samp{logical.names} within \samp{print.xtab} finds that the column margin names are one of FALSE/TRUE, 0/1 or NO/YES in those orders, the risk of the column variable for the second level of the row variable relative to the first row variable will be displayed as well. } \value{nil} \author{Jim Lemon} \seealso{\link{calculate.xtab}, \link{xtab}} \keyword{misc} prettyR/man/brkdn.Rd0000755000176200001440000000304612710102643014067 0ustar liggesusers\name{brkdn} \alias{brkdn} \title{Breakdown of a numeric variable by grouping variable(s)} \description{ Calculates means, variances and ns for subgroups of numeric observations and displays the results. } \usage{ brkdn(formula,data,maxlevels=10,num.desc=c("mean","var","valid.n"), width=10,round.n=2) } \arguments{ \item{formula}{a formula with the variable to be broken down on the left and the names of one or more variables defining subgroups on the right} \item{data}{the data frame from which to select the variables} \item{maxlevels}{the maximum number of levels in any subgroup} \item{num.desc}{names of the summary functions to apply to the variable on the left side of the formula} \item{width}{The number of characters to allow for each column in the summary output.} \item{round.n}{The number of decimal places to round the output.} } \details{ \samp{brkdn} will accept a formula referring to columns in a data frame. It calls \samp{describe.numeric} for the calculations and displays a table of results. } \value{ The results of \samp{describe.numeric}, or a multi-level list if more than one grouping variable is specified.} \author{Jim Lemon} \seealso{\link{describe.numeric}} \examples{ test.df<-data.frame(Age=rnorm(100)+3*10,Sex=sample(c("M","F"),100,TRUE), Employ=sample(c("FT","PT","NO"),100,TRUE)) # add value labels for Employ in alphabetical order so they match attr(test.df$Employ,"value.labels")<-c("Full time","None","Part time") brkdn(Age~Sex+Employ,test.df) } \keyword{misc} prettyR/man/CreateIndexFile.Rd0000755000176200001440000000143312710102643015760 0ustar liggesusers\name{CreateIndexFile} \alias{CreateIndexFile} \title{Write an index file for the current output (htmlize).} \description{Write an index file for the current HTML output.} \usage{CreateIndexFile(HTMLbase,HTMLdir,title="R listing")} \arguments{ \item{HTMLbase}{The base name for the HTML files.} \item{HTMLdir}{The directory in which to write the HTML files.} \item{title}{The title for the listing.} } \details{ \samp{CreateIndexFile} opens a new HTML index file. If there is another file with the same name, it will be overwritten. This is intentional, as the user may want to run \samp{htmlize} repeatedly without generating multiple sets of files. It then writes the frameset definition into the file and closes it. } \value{nil} \author{Jim Lemon} \keyword{misc} prettyR/man/stretch_df.Rd0000644000176200001440000000377312710102643015120 0ustar liggesusers\name{stretch_df} \alias{stretch_df} \title{ Reshape a data frame from "long" to "wide" format } \description{ Reshape a data frame by reducing the multiple rows of repeated variables to a single row for each instance (usually a "case" or object) and stretching out the variables that are not repeated within each case. } \usage{ stretch_df(x,idvar,to.stretch,ordervar=NA,include.ordervar=TRUE) } \arguments{ \item{x}{A data frame.} \item{idvar}{A variable that identifies instances (cases or objects).} \item{to.stretch}{Which variables are to be stretched out in the single row.} \item{ordervar}{Variable that gives the order of the stretched variables.} \item{include.ordervar}{Include the ordering variable in the output.} } \details{ \samp{stretch_df} takes a data frame in which at least some instances have multiple rows and reshapes it into a "wide" format with one row per instance. The variable passed as \samp{idvar} distinguishes the instances, and will be the first column in the new data frame. All other variables in the data frame except those named in \samp{to.stretch} and \samp{ordervar} will follow \samp{idvar}. The variables named in \samp{to.stretch} will follow the variables that are not repeated in the initial data frame, along with the order variable if \samp{include.ordervar} is TRUE. } \note{ \samp{stretch_df} mostly does what other reshaping functions can do, but may be more easy to understand. It will stretch multiple variables, something that some reshaping functions will not do. } \value{The reshaped data frame.} \author{Jim Lemon} \seealso{\link{reshape}} \examples{ # create a data frame with two repeated variables longdf<-data.frame(ID=c(rep(111,3),rep(222,4),rep(333,6),rep(444,3)), name=c(rep("Joe",3),rep("Bob",4),rep("Sue",6),rep("Bea",3)), score1=sample(1:10,16,TRUE),score2=sample(0:100,16), scoreorder=c(1,2,3,4,3,2,1,4,6,3,5,1,2,1,2,3)) stretch_df(longdf,"ID",c("score1","score2"),"scoreorder") } \keyword{misc} prettyR/man/addxtabs.Rd0000755000176200001440000000347212710102643014564 0ustar liggesusers\name{addxtabs} \alias{addxtabs} \title{ Add the cells of two or more xtab objects } \description{ Adds the counts in corresponding cells of xtab objects } \usage{ addxtabs(x) } \arguments{ \item{x}{A list containing two or more return values from \samp{xtab}.} } \details{ \samp{addxtabs} adds the counts in the cells of two or more \samp{xtab} objects by matching the row and column names. All of the \samp{xtab} objects in the list will usually contain counts of the same response options, although some options may be missing in some tables. This often occurs when respondents do not have to complete all of the responses (e.g. "for up to three occasions ..."). This function facilitates calculating the total counts in crosstabulations that arise from multiple responses for the options. See the example. } \value{The number of valid values or the length of the object.} \author{Jim Lemon} \seealso{\link{xtab}} \examples{ # Assume that respondents are asked to record the location and quantity for # three occasions of drinking, and for each occasion the fields are named # "drinks" and "loc" drinkloc<-data.frame(drinks1=sample(c("1-2","3-5","6+"),100,TRUE), loc1=sample(c("Meal at home","Restaurant","Party","Pub"),100,TRUE), drinks2=sample(c("1-2","3-5","6+"),100,TRUE), loc2=sample(c("Meal at home","Restaurant","Party","Pub"),100,TRUE), drinks3=sample(c("1-2","3-5"),100,TRUE), loc3=sample(c("Meal at home","Restaurant","Party"),100,TRUE)) # notice how two options have been left out in drink3 and loc3 # create the list of xtab objects dltablist<-list() dltablist[[1]]<-xtab(loc1~drinks1,drinkloc) dltablist[[2]]<-xtab(loc2~drinks2,drinkloc) dltablist[[3]]<-xtab(loc3~drinks3,drinkloc) # now sum the corresponding cells addxtabs(dltablist) } \keyword{misc} prettyR/man/xtab.Rd0000755000176200001440000000465713452515543013751 0ustar liggesusers\name{xtab} \alias{xtab} \title{Crosstabulate variables} \description{Crosstabulates variables with small numbers of unique values.} \usage{ xtab(formula,data,varnames=NULL,or=TRUE,chisq=FALSE,phi=FALSE,html=FALSE, bgcol="lightgray",lastone=TRUE) } \arguments{ \item{formula}{a formula containing the variables to be crosstabulated} \item{data}{the data frame from which to select the variables} \item{varnames}{optional labels for the variables (defaults to \samp{names(data))}} \item{or}{whether to calculate the odds ratio (only for 2x2 tables).} \item{chisq}{logical - whether to display chi squared test(s) of the table(s)} \item{phi}{whether to calculate and display the phi coefficient of association - only for 2x2 tables} \item{html}{whether to format the resulting table with HTML tags.} \item{bgcol}{background color for the table if html=TRUE.} \item{lastone}{A flag that controls the names of the returned list.} } \details{ \samp{xtab} will accept a formula referring to columns in a data frame or two explicit variable names. It calls \samp{calculate.xtab} for the calculations and displays one or more tables of results by calling \samp{print.xtab}. If \samp{html} is TRUE, the resulting table will be formatted with HTML tags. The default value of \samp{lastone} should not be changed. } \value{ The result of \samp{calculate.xtab} if there is only one table to display, otherwise a nested list of tables.} \author{Jim Lemon} \seealso{ \link{table}, \link{calculate.xtab}, \link{print.xtab} } \examples{ test.df<-data.frame(sex=sample(c("MALE","FEMALE"),1000,TRUE), suburb=sample(1:4,1000,TRUE),social.type=sample(LETTERS[1:4],1000,TRUE)) xtab(sex~suburb+social.type,test.df,chisq=TRUE) # now add some value labels attr(test.df$suburb,"value.labels")<-1:4 names(attr(test.df$suburb,"value.labels"))<- c("Upper","Middle","Working","Slum") attr(test.df$social.type,"value.labels")<-LETTERS[1:4] names(attr(test.df$social.type,"value.labels"))<- c("Gregarious","Mixer","Aloof","Hermit") xtab(sex~suburb+social.type,test.df) # now have some fun with ridiculously long factor labels testxtab<-data.frame(firstbit=sample(c("Ecomaniacs","Redneck rogues"),50,TRUE), secondbit=sample(c("Macho bungy jumpers","Wimpy quiche munchers"),50,TRUE)) # and format the table in HTML and add some tests xtab(secondbit~firstbit,testxtab,html=TRUE,chisq=TRUE,phi=TRUE) } \keyword{misc} prettyR/man/print.freq.Rd0000755000176200001440000000214412710102643015055 0ustar liggesusers\name{print.freq} \alias{print.freq} \title{Display frequency table(s)} \description{ Displays one or more frequency tables produced by \samp{freq}. } \usage{ \method{print}{freq}(x,show.pc=TRUE,cum.pc=FALSE,show.total=FALSE,...) } \arguments{ \item{x}{a frequency table produced by \samp{\link{freq}}} \item{show.pc}{Whether to display percentages as well as counts.} \item{cum.pc}{Whether to display cumulative percentages.} \item{show.total}{Whether to display the total count of observations.} \item{...}{additional arguments passed to \samp{print}.} } \details{ \samp{print.freq} displays frequency tables produced by \samp{freq}. If \samp{show.pc} is TRUE and there is a value in the frequency table with the label "NA", an additional set of percentages ignoring that value will also be displayed. If \samp{show.total} is TRUE, the total number of observations will be displayed. } \value{nil} \author{Jim Lemon} \seealso{\link{freq}} \examples{ test.df<-data.frame(A=c(sample(1:10,99,TRUE),NA),C=sample(LETTERS,100,TRUE)) test.freq<-freq(test.df) print(test.freq,show.total=TRUE) } \keyword{misc} prettyR/man/htmlize.Rd0000755000176200001440000001212612710102643014442 0ustar liggesusers\name{htmlize} \alias{htmlize} \title{Read an R script and write HTML output} \description{Produces HTML output from an R script.} \usage{htmlize(Rfile,HTMLbase,HTMLdir,title, bgcolor="#dddddd",echo=FALSE,do.nav=FALSE,useCSS=NULL,...)} \arguments{ \item{Rfile}{The R script file from which to read the commands.} \item{HTMLbase}{The base name for the HTML files (see Details).} \item{HTMLdir}{The directory in which to write the HTML output.} \item{title}{The title of the HTML page and the headings for the frames. See Details for including the title in the R script.} \item{bgcolor}{The background color for the frames.} \item{echo}{Whether to include ("echo") the commands in the listing.} \item{do.nav}{Whether to have a navigation window.} \item{useCSS}{The name of a CSS stylesheet that will define the appearance of components of the HTML display. If this is not NULL, the CSS file should exist.} \item{...}{Additional arguments - currently ignored.} } \details{ \samp{htmlize} allows the user to produce a basic HTML listing from an existing R script. The script must already run correctly with \samp{source}. If the first line of the R script is a comment starting with \samp{#title~} and the \samp{title} argument is missing, the rest of the first line will be used as the title of the HTML output. If there is any graphic output, the script must contain the necessary commands to set up the graphic devices. Note that only TIFF, GIF, BMP, JPEG and PNG graphic images are generally viewable in HTML browsers. The last two are probably the most reliable, but see their help pages for more details. The graphic files will be linked to the HTML listing page so that they should be interleaved with text output and commands. If \samp{do.nav} is TRUE, three files will be output. The first will be named \samp{HTMLbase.html}, where \samp{HTMLbase} is whatever string has been passed as that argument. If that argument is missing, the function will attempt to munge the \samp{Rfile} argument into a base name. This file is an "index" file that sets up the HTML frameset. The second file will be named \samp{HTMLbase_nav.html} and will be dispayed at the left side of the HTML output as a "navigation" list using the commands as names. Commands longer than 20 characters will be truncated. The third file, named \samp{HTMLbase_list.html}, contains the program listing. All three files will be written in \samp{HTMLdir}. If this is missing, the path of \samp{Rfile} will be used. If \samp{do.nav} is FALSE, only one file will be written. It will have the same content as the \samp{HTMLbase_list.html} file except without the name tags for navigation and it will be named \samp{HTMLbase.html}. Commands that create or alter connections, such as \samp{sink} are "forbidden", not evaluated and marked as comments in the listing. This prevents such commands from altering the connections necessary to write the HTML files. If there is a function defined in the R script, \samp{htmlize} will run, but not write any output after the function definition. This has to do with the way that \samp{htmlize} reads command lines from the script file. This is a bug, so watch this space for a solution. The ability to nominate a CSS stylesheet allows the user to customize the appearance of the HTML output. The most likely use of the \samp{useCSS} argument is for the user to specify whatever aspects of the HTML display are to be different from the default browser values in a stylesheet. } \note{ As of version 1.1, both \samp{echo} and \samp{do.nav} are FALSE by default, as these defaults seem to be more popular. The major differences between \samp{htmlize} and \samp{R2html} are: \samp{htmlize} will run with a minimum of one argument (\samp{Rfile}) and produces very basic HTML output. It requires the graphic devices to be set up as commands in the R script. \samp{R2html} does not require commands for graphic devices, just comments at the end of any line that requires graphic output to the HTML file. It color codes commands and output and is more careful about the content of lines it writes. } \value{nil} \author{Jim Lemon with improvements by Phillipe Grosjean} \examples{ rcon<-file("test.R","w") cat("#title~This is the title\n") cat("test.df<-data.frame(a=factor(sample(LETTERS[1:4],100,TRUE)),\n", file=rcon) cat(" b=sample(1:4,100,TRUE),c=rnorm(100),d=rnorm(100))\n",file=rcon) cat("describe(test.df)\n",file=rcon) cat("print(freq(test.df$a))\n",file=rcon) cat("xtab(a~b,test.df)\n",file=rcon) cat("brkdn(c~b,test.df)\n",file=rcon) cat("png(\"hista.png\")\nhist(test.df$b)\ndev.off()\n",file=rcon) cat("png(\"plotcd.png\")\nplot(test.df$c,test.df$d)\ndev.off()\n",file=rcon) close(rcon) # call htmlize with minimal arguments htmlize("test.R") # if you want to see the output, use the following line # system(paste(options("browser")," file:",getwd(),"/test.html",sep="",collapse="")) # to clean up, use the following line # system("rm test.R test.html hista.png plotcd.png") } \keyword{misc} prettyR/man/delim.table.Rd0000755000176200001440000001207613445345043015163 0ustar liggesusers\name{delim.table} \alias{delim.table} \title{Format a 2D table} \description{Format a 2D table with delimiters and other formatting commands} \usage{ delim.table(x,filename="",delim=",",tabegin="",bor="",eor="\n",tablend="", label=deparse(substitute(x)),header=NULL,trailer=NULL,html=FALSE, show.rownames=TRUE,leading.delim=FALSE,show.all=FALSE,nsignif=4, con,open.con=FALSE) } \arguments{ \item{x}{A list, matrix or data frame that is to be formatted.} \item{filename}{Name for a file to which the result will be written.} \item{delim}{The delimiter to place between entries in the table(s).} \item{tabegin}{Any formatting commands to be placed before the table.} \item{bor}{The formatting command for the beginning of a table row.} \item{eor}{The formatting command for the end of a table row.} \item{tablend}{Any formatting commands to be placed after the table.} \item{label}{A label to be displayed before the table.} \item{header}{A character string to be written at the beginning of the output file.} \item{trailer}{A character string to be written at the end of the output file.} \item{html}{If TRUE, all table formatting commands that are not explicitly specified will be altered to HTML tags.} \item{show.rownames}{Whether to display the rownames of a table.} \item{leading.delim}{Whether to add an extra delimiter at the beginning of the table. See Details.} \item{show.all}{Whether to show all the components of a list. The default FALSE is to show only those components that look like 2D tables.} \item{nsignif}{Number of significant digits for numeric display.} \item{con}{A connection to which the output will be written. If a filename is passed, it will be ignored if \samp{con} is not missing.} \item{open.con}{A flag for an open connection. This argument is used by the function to keep track of connections in recursive calls and should not be altered by the user.} } \value{ nil } \details{ \samp{delim.table} tries to format its first argument into one or more tables that will be displayed in another application. The most common use is to produce a CSV style file that can be imported into a spreadsheet. The default values for \samp{delim} and \samp{eor} should be adequate for this, and all the user has to do is to supply a filename as in the first example. When a filename is provided, the function attempts to open the file, write its output to it and close it again. In order to deal with the multilevel lists that are often produced by other functions, the function calls itself until it reaches the lowest level of the list, where it can successfully format the contents. Thus the function only passes the connection, not the filename, in recursive calls. If the user passes both a filename and a valid connection, the output will be written to the connection and the filename will not be used. \samp{delim.table} will fail if passed a table with more than two dimensions. However, the function will process 2D "slices" of such tables if called with one of the \samp{apply} family of functions or manually for each slice. \samp{delim.table} can also be used to format HTML tables as in the second example. If the user wants different tags from the defaults, pass these explicitly. In principle, any markup language that can produce a table using commands that include; commands to begin and end the table, a command to start and end a row, and a command to start a new cell. \samp{delim.table} is consistent with the default CSV arguments, adding an extra delimiter to the first line if there are row names. The user should set \samp{leading.delim} to FALSE for a table without the empty cell at the upper left. When \samp{delim.table} is used to format tables for \samp{htmlize}, it should not attempt to open a new connection. An unexpected use of \samp{delim.table} is producing tables that can be imported into OpenOffice Writer and most other word processors. While the tables in an HTML listing can be imported directly, the formatting is usually not suitable. If a table is output to an HTML or text document formatted with TAB characters as the delimiter as in the third example, the output can be copied and pasted into the word processor document and then converted to a table. } \author{Jim Lemon} \seealso{\link{htmlize}} \examples{ testdf<-data.frame(a=sample(0:1,100,TRUE),b=rnorm(100),c=rnorm(100)) testglm<-summary(glm(a~b*c,testdf,family="binomial")) # produce a CSV file to import into a spreadsheet, just the coefficients delim.table(testglm$coefficients,"testglm.csv") # now create an HTML file of the three tables in the result # add a background color different from the default delim.table(testglm,"testglm.html",header="", html=TRUE) # these tables can be pasted into a word processor and converted # using "Insert|Table" or similar commands delim.table(testglm,"testglm.tab",delim="\t",leading.delim=FALSE) # to clean up, delete the files "testglm.csv", "testglm.tab" and "testglm.html" } \keyword{misc} prettyR/man/StartNav.Rd0000755000176200001440000000115712710102643014532 0ustar liggesusers\name{StartNav} \alias{StartNav} \title{Write the header for the HTML navigation file (R2html).} \description{Initiate the navigation file for an R listing in HTML format.} \usage{StartNav(navcon,title="R listing",bgcolor="#dddddd")} \arguments{ \item{navcon}{The connection for writing to the navigation file.} \item{title}{Title for the navigation window.} \item{bgcolor}{The background color for the navigation frame.} } \details{ \samp{StartNav} sets up the file with the navigation frame information for the HTML listing for \samp{R2html}. } \value{nil} \author{Philippe Grosjean} \keyword{misc}