Skip to content

Instantly share code, notes, and snippets.

View rmflight's full-sized avatar

Robert M Flight rmflight

View GitHub Profile
@rmflight
rmflight / setupknitr.md
Created June 15, 2012 18:44
knitr setup for Rmd files

This code block goes at the top of every Rmd file that I create for eventual conversion by knitr

# sets output for inline results nicely
knit_hooks$set(inline = identity) 

# kills knitr if there is an error, therefore we don't waste time generating error messages
knit_hooks$set(error = function(x, options) stop(x)) 

# these are extremely useful options for working in R
@rmflight
rmflight / customCDF.Rmd
Created July 14, 2012 02:31
custom CDF in R / Bioconductor
# Creating custom CDF for Affy chips in R / Bioconductor
```{r knitrOpts, echo=FALSE}
knit_hooks$set(inline = identity) # sets output for inline resutls nicely
knit_hooks$set(error = function(x, options) stop(x)) # kills knitr if there
# is an error, therefore we don't waste time generating error messages
options(save.defaults=list(compress="xz"), stringsAsFactors=FALSE)
# set up the default compression, and do NOT allow strings in data frames to become factors.
# That one is really important, and continually messes me up.
startTime <- Sys.time() # when did we start
@rmflight
rmflight / RmdLinks.Rmd
Created July 26, 2012 20:35
Rmd programmatic links
@rmflight
rmflight / difftimeKnitr.Rmd
Created August 15, 2012 17:58
working with difftime objects in knitr
If you want to display time elapsed nicely in an Rmd object generated by knitr, here is my suggesion:
```{r diffT}
t1 <- Sys.time()
Sys.sleep(5)
t2 <- Sys.time()
tDiff <- difftime(t2, t1, units="hours")
```
This process took `r format(tDiff)`. Note that units above can be whatever unit you want, see ?difftime.
@rmflight
rmflight / ggplotSolutions
Created August 30, 2012 15:05
ggplot2 solutions to common problems
http://stackoverflow.com/questions/5328452/overlaid-histograms-in-r-ggplot2-preferred
http://stackoverflow.com/questions/6939136/how-to-overlay-density-plots-in-r
@rmflight
rmflight / githubPages.md
Created September 17, 2012 15:55
useful websites: github pages, blogging, etc

How to host a blog using github

http://mbmccormick.com/2011/10/ditching-wordpress-for-jekyll-and-github/

How to do figure captions in knitr / markdown

yihui/knitr#81

use \caption{} and \label{} in latex; use in HTML; use caption in markdown

From the options manual: eval.after: (NULL) a character vector of option names; these options will be evaluated after a chunk is evaluated, and all other options will be evaluated before a chunk (e.g. for chunk option fig.cap=paste('p-value is', t.test(x)$p.value), it will be evaluated after the chunk according to the value of x if eval.after='fig.cap')

@rmflight
rmflight / changeMDRender.r
Created September 18, 2012 20:06
change md rendering function in RStudio
options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
require(markdown)
htmlOptions <- markdownHTMLOptions(defaults=TRUE)
htmlOptions <- htmlOptions[htmlOptions != "hard_wrap"]
markdownToHTML(inputFile, outputFile, options = htmlOptions)
}
)
@rmflight
rmflight / tableFigureFuncs.r
Created October 9, 2012 13:54
knitr table and figure functions for Rmd
pasteLabel <- function(preText, inObj, objName, insLink=TRUE){
objNum <- inObj[objName]
useText <- paste(preText, objNum, sep=" ")
if (insLink){
useText <- paste("[", useText, "](#", objName, ")", sep="")
}
useText
}
@rmflight
rmflight / htmlpub.css
Created October 17, 2012 18:52
html publication gist
body {
box-sizing: border-box;
font-size: 16px;
font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
width:800px;
margin: auto;
}
@rmflight
rmflight / presentations.bib
Created October 19, 2012 13:43
reproducible problems of knit and knit2html rstudio buttion
@article{Lord1994,
abstract = {Describes the Autism Diagnostic Interview-Revised (ADI-R), a revision of the Autism Diagnostic Interview, a semistructured, investigator-based interview for caregivers of children and adults for whom autism or pervasive developmental disorders is a possible diagnosis. The revised interview has been reorganized, shortened, modified to be appropriate for children with mental ages from about 18 months into adulthood and linked to ICD-10 and DSM-IV criteria. Psychometric data are presented for a sample of preschool children.},
author = {Lord, C and Rutter, M and {Le Couteur}, A},
issn = {0162-3257},
journal = {Journal of autism and developmental disorders},
keywords = {Algorithms,Autistic Disorder,Autistic Disorder: classification,Autistic Disorder: diagnosis,Autistic Disorder: psychology,Caregivers,Caregivers: psychology,Child,Female,Humans,Intellectual Disability,Intellectual Disability: classification,Intellectual Disability: diagnosis,Intellectual Disabi