This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gather_idx <- match(gather_cols, names(data)) | |
if (anyNA(gather_idx)) { | |
missing_cols <- paste(gather_cols[is.na(gather_idx)], collapse = ", ") | |
stop("Unknown column names: ", missing_cols, call. = FALSE) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add to .Rmd file and place the a custom.css file with the desired css in the same directory | |
options(rstudio.markdownToHTML = | |
function(inputFile, outputFile) { | |
require(markdown) | |
markdownToHTML(inputFile, outputFile, stylesheet='custom.css') | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages <- c( | |
"bear", | |
"data.table", | |
"deSolve", | |
"devtools", | |
"dplyr", | |
"formatR", | |
"ggplot2", | |
"gridExtra", | |
"installr", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Simplified loading and installing of packages | |
#' | |
#' This is a wrapper to \code{\link{require}} and \code{\link{install.packages}}. | |
#' Specifically, this will first try to load the package(s) and if not found | |
#' it will install then load the packages. Additionally, if the | |
#' \code{update=TRUE} parameter is specified it will check the currently | |
#' installed package version with what is available on CRAN (or mirror) and | |
#' install the newer version. | |
#' | |
#' @param pkgs a character vector with the names of the packages to load. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#’ Create a Kaplan-Meier plot using ggplot2 | |
#’ | |
#’ @param sfit a \code{\link[survival]{survfit}} object | |
#’ @param returns logical: if \code{TRUE}, return an ggplot object | |
#’ @param xlabs x-axis label | |
#’ @param ylabs y-axis label | |
#’ @param ystratalabs The strata labels. \code{Default = levels(summary(sfit)$strata)} | |
#’ @param ystrataname The legend name. Default = “Strata” | |
#’ @param timeby numeric: control the granularity along the time-axis | |
#’ @param main plot title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("shiny") | |
library("plotly") | |
library("ggplot2") | |
shinyServer(function(input, output) { | |
output$text <- renderText({ | |
ggiris <- qplot(Petal.Width, Sepal.Length, data=iris, color=Species) | |
py <- plotly("RgraphingAPI", "ektgzomjbx") | |
res <- py$ggplotly(ggiris) | |
iframe <- paste("<iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:9f8cc010920e3ba427bf8782337a847d8f5129fe6b3a868aad7eeaa6fb3187c2" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Get URLs to blog post full text for all posts | |
#' by scraping them out of each page of the | |
#' main blog aggregator | |
# from: https://github.com/benmarwick/dayofarchaeology/blob/master/001_scrape_for_links_to_fulltext.r | |
library(RCurl) | |
library(XML) | |
n <- 100 # determined by inspecting the first page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
save.xlsx <- function (file, ...) | |
{ | |
require(xlsx, quietly = TRUE) | |
objects <- list(...) | |
fargs <- as.list(match.call(expand.dots = TRUE)) | |
objnames <- as.character(fargs)[-c(1, 2)] | |
nobjects <- length(objects) | |
for (i in 1:nobjects) { | |
if (i == 1) | |
write.xlsx(objects[[i]], file, sheetName = objnames[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import string | |
import tempfile | |
import subprocess | |
def random_id(length=8): | |
return ''.join(random.sample(string.ascii_letters + string.digits, length)) | |
TEMPLATE_SERIAL = """ |
OlderNewer