Skip to content

Instantly share code, notes, and snippets.

View egouldo's full-sized avatar

Elliot Gould egouldo

View GitHub Profile
tell application "Bookends"
set theIDs to «event ToySRUID» "Selection"
repeat with theID in paragraphs of theIDs
tell front library window
try
set myRefs to (publication items whose id is theID)
set myItem to first item of myRefs
set thePath to path of attachment items of myItem
tell application "Bookends"
tell front library window
set theIDs to get id of publication items of group item "Unlinked Attachments"
repeat with theID in theIDs
try
set myRefs to (publication items whose id is theID)
set myItem to first item of myRefs
set {theKey, thePath, theAuthor, theEditor, theTitle} to {citekey, path of attachment items, authors, editors, title} of myItem
if theAuthor = "" then set theAuthor to theEditor
set theRIS to format myItem using "RIS.fmt"
@egouldo
egouldo / countsToCases.R
Last active July 24, 2017 11:14
Convert contingency table (counts) to cases
# Source: http://www.cookbook-r.com/Manipulating_data/Converting_between_data_frames_and_contingency_tables/#countstocases-function
# Convert from data frame of counts to data frame of cases.
# `countcol` is the name of the column containing the counts
countsToCases <- function(x, countcol = "Freq") {
# Get the row indices to pull from x
idx <- rep.int(seq_len(nrow(x)), x[[countcol]])
# Drop count column
x[[countcol]] <- NULL
@jennybc
jennybc / photo-gallery-README.R
Last active April 3, 2022 19:21
Generate a photo-gallery README for a directory of figs
@stla
stla / global.R
Created November 6, 2013 10:51
Shiny: dynamic number of tabs and tab-dependent UI in the sidebar
## generates two datasets for illustration
I <- 3 # nb tests
J <- 4 # nb timepoints
dat1 <- data.frame(
Test=gl(I,J,labels=LETTERS[1:I]),
timepoint=rep(1:J,I)
)
dat1 <- transform(dat1, y=round(rnorm(I*J,2*timepoint),1))
I <- 5 # nb tests
J <- 3 # nb timepoints
@Thell
Thell / Exmple.Rmd
Created June 20, 2013 23:59
R markdown to illustrate creation of in-document referencing for chunks, sections, pages, and such.
```{r setup, echo=FALSE, results='hide'}
chunkref <- local({
function(chunklabel) {
sprintf('[%s](#%s)', chunklabel, chunklabel )
}
})
secref <- local({
function(seclabel) {
sprintf('[%s](#%s)', seclabel, seclabel )
@dfalster
dfalster / addNewData.R
Last active February 19, 2023 00:29
The function addNewData.R modifies a data frame with a lookup table. This is useful where you want to supplement data loaded from file with other data, e.g. to add details, change treatment names, or similar. The function readNewData is also included. This function runs some checks on the new table to ensure it has correct variable names and val…
##' Modifies 'data' by adding new values supplied in newDataFileName
##'
##' newDataFileName is expected to have columns
##' c(lookupVariable,lookupValue,newVariable,newValue,source)
##'
##' Within the column 'newVariable', replace values that
##' match 'lookupValue' within column 'lookupVariable' with the value
##' newValue'. If 'lookupVariable' is NA, then replace *all* elements
##' of 'newVariable' with the value 'newValue'.
##'
@stephenturner
stephenturner / arrange_ggplot2.R
Created September 14, 2012 21:30
Arrange ggplot2 plots
## Function for arranging ggplots. use png(); arrange(p1, p2, ncol=1); dev.off() to save.
require(grid)
vp.layout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y)
arrange_ggplot2 <- function(..., nrow=NULL, ncol=NULL, as.table=FALSE) {
dots <- list(...)
n <- length(dots)
if(is.null(nrow) & is.null(ncol)) { nrow = floor(n/2) ; ncol = ceiling(n/nrow)}
if(is.null(nrow)) { nrow = ceiling(n/ncol)}
if(is.null(ncol)) { ncol = ceiling(n/nrow)}
## NOTE see n2mfrow in grDevices for possible alternative
@yihui
yihui / README.md
Last active June 30, 2021 18:01
Preview all syntax highlighting themes in knitr (HTML and LaTeX)