]> code.communitydata.science - cdsc_tex.git/blob - paper_template/resources/preamble.R
Merge branch 'master' into knitr
[cdsc_tex.git] / paper_template / resources / preamble.R
1 bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
2 gray <- function(x) {paste('{\\textcolor{gray}{',x,'}}', sep ='')}
3 wrapify <- function (x) {paste("{", x, "}", sep="")}
4
5 # load("knitr_data.RData"); now broken up into small files so we'll bring 'em all in together
6 r <- do.call("c", lapply(paste("knitr_rdata/", list.files("knitr_rdata"), sep=""),
7                          function (x) {load(x); return(r)}))
8
9 attach(r)
10
11 f <- function (x) {formatC(x, format="d", big.mark=',')}
12
13 format.percent <- function(x) {paste(f(x*100),"\\%",sep='')}
14
15 format.day.ordinal <- function(x) {
16     day <- format(x,format="%d")
17     daylast <- substr(day,nchar(day),nchar(day))
18     dayfirst <- substr(day,1,1)
19     if(dayfirst == '0')
20         day = daylast
21
22     if( daylast == "1")
23         day <- paste0(day,"st")
24     else if(daylast == "2")
25         day <- paste0(day,"nd")
26     else if (daylast == "3")
27         day <- paste0(day,"rd")
28     else
29         day <- paste0(day,"th")
30         
31     return(day)
32 }
33
34 format.month <- function(x){
35     return( format(x,format='%B %Y'))
36 }
37
38 format.date <- function(x) {
39     return(paste(format(x,format = '%B'),format.day.ordinal(x),format(x,format='%Y'),sep=' '))
40 }
41
42 format.pvalue <- function (x, digits=3) {
43     threshold <- 1*10^(-1*digits)
44     x <- round(x, digits)
45     if (x < threshold) {
46         return(paste("p<", threshold, sep=""))
47     } else {
48         return(paste("p=", x, sep=""))
49     }
50 }

Community Data Science Collective || Want to submit a patch?