Skip to content

Instantly share code, notes, and snippets.

@karthik
karthik / markdownTable.R
Created October 15, 2012 11:07
a function to generate Pandoc compatible markdown tables from R
#' A function to generate markdown tables for R data
#'
#' This function willl generate pandoc compatible markdown for tables from R data
#' @param df a \code{data.frame}
#' @param headings = NULL headings to use if one desires something other than default \code{data.frame} column names
#' @export
#' @examples \dontrun{
#' markdownTable(mtcars)
#'}
@karthik
karthik / plyr_bug.R
Created November 21, 2012 17:44
how to reproduce my plyr bug
# Download and open this data file, size = 1.4mb
# https://dl.dropbox.com/u/2223411/results_list.rda
load('results_list.rda')
class(results)
# 1] "list"
length(results)
# [1] 72860
@karthik
karthik / workshop.md
Created November 27, 2012 06:23
Abstract for R data viz workshop.

Workshop: Data visualization using R

Organizers: Andrew Trednnick, Karthik Ram, Naupaka Zimmerman
Speakers: Naupaka Zimmerman, ...

R is one of the most widely used tools for statistical analysis in the academic community. In addition to the large suite of analytical tools, R is also capable of producing publication quality figures that can easily be embedded into publications, presentations, and lab notebooks. In this workshop we will demonstrate some of these tools, notably the functionality in the ggplot2 library (and associated packages). We will provide some example datasets beforehand but feel free to bring your own along with your laptop and a pre-installed copy of R or RStudio to participate.

@karthik
karthik / mvspec.R
Created December 1, 2012 20:55
mvspec
#'mvspec2b
#'
#' Description not yet complete since function isn't.
#'@param x matrix of (multi-variate) time-series in columns. For 'pgram' - which assumes even sampling - x must be a time-series (ts) object with the sampling frequency specified. Although 'lombscargle' will also work on a ts object, a ts object assumes even sampling and therefore can't be used. If 'lombscargle' is used on evenly sampled data, virtually the same result as the 'pgram' method will be returned.
#'@param type Method used to estimate spectral density. Options are 'pgram' or 'lombscargle' (default) or 'fft' (from cts package - not checked for correctness).
#'@param time_s (optional, required for Lomb-Scargle) Vector of time-points. time_s points may be unevenly spaced, but for multi-species time-series are assumed to the same for all species.
#'@param spans <what param does>
#'@param kernel <what param does>
#'@param taper = 0.1 <what param does>
#'@param pad = 0 <what param does>
@karthik
karthik / test_API.R
Created December 6, 2012 18:49
A function to test API status and return a logical TRUE if it responds.
# This is required for evalWithTimeout
suppressPackageStartupMessages(library(R.utils))
#'Function to test whether an API is down and if so, throw an error.
#'
#' @param test_fn The function call to test
#' @param tlimit = 120 A timeout in seconds
#' @return logical
#' @examples \dontrun{
#' api_status(eol_search('Salix'))
#'mvspec2b
#'
#' Description not yet complete since function isn't.
#'@param x matrix of (multi-variate) time-series in columns. For 'pgram' - which assumes even sampling - x must be a time-series (ts) object with the sampling frequency specified. Although 'lombscargle' will also work on a ts object, a ts object assumes even sampling and therefore can't be used. If 'lombscargle' is used on evenly sampled data, virtually the same result as the 'pgram' method will be returned.
#'@param type Method used to estimate spectral density. Options are 'pgram' or 'lombscargle' (default) or 'fft' (from cts package - not checked for correctness).
#'@param time_s (optional, required for Lomb-Scargle) Vector of time-points. time_s points may be unevenly spaced, but for multi-species time-series are assumed to the same for all species.
#'@param spans <what param does>
#'@param kernel <what param does>
#'@param taper = 0.1 <what param does>
#'@param pad = 0 <what param does>
@karthik
karthik / gbifmap2.R
Created December 10, 2012 22:52
A refined gbifmap
#' Make a simple map to visualize GBIF data.
#'
#' Basic function to plot your lat/long data on a map.
#'
#' @import ggplot2 maps
#' @param input Either a single data.frame or a list of data.frame's (e.g., from
#' different speies). The data.frame has to have, in addition to any other
#' columns, columns named exactly "decimalLatitude" and "decimalLongitude".
#' @param mapdatabase The map database to use in mapping. What you choose here
#' determines what you can choose in the region parameter. One of: county,
@karthik
karthik / server.R
Created December 10, 2012 22:57
rgif data test
library(shiny)
library(ggplot2)
library(rgbif)
## Set up server output
load('/home/karthik/ShinyApps/rgbif/results.rda')
shinyServer(function(input, output) {
# define function for server plot output
output$gbifplot <- reactivePlot(function() {
print(gbifmap(results[input$spec]))
@karthik
karthik / dois_from_bibtex.R
Created December 18, 2012 02:07
How to grab dois from a bibtex file.
library(bibtex)
library(plyr)
# If you don't have the above mentioned packages, just run
# install.packages(package_name) before running this code.
#
# My bib file that I've used as an example
bib_raw <- read.bib('~/Desktop/citation_counts/PLOS_refs.bib')
# Once read in, the doi is a slot under each list item.
dois <- llply(bib_raw, function(x) {
return(x$doi)
// ==UserScript==
// @name Replace Text On Webpages
// @namespace http://userscripts.org/users/23652
// @description Replaces text on websites. Now supports wildcards in search queries. Won't replace text in certain tags like links and code blocks
// @include http://*
// @include https://*
// @exclude http://userscripts.org/scripts/review/*
// @copyright JoeSimmons
// @version 1.0.52
// @license http://creativecommons.org/licenses/by-nc-nd/3.0/us/