This file contains hidden or 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(data.table) | |
x <- data.table(A = c(3,2,1), B = 4:6) | |
y <- data.table(A = 1:4, C = 5:8) | |
z <- data.table(A = 2:3, D = 5:6) | |
tbls <- list(x, y, z) | |
lapply(tbls, function(i) setkey(i, A)) | |
merged <- Reduce(function(...) merge(..., all = T), tbls) |
This file contains hidden or 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
#' Grouped mutate | |
#' | |
#' Group by columns, then mutate, and then regroup to previous groups. | |
#' @param .data data frame | |
#' @param .by character vector with columns to group by | |
#' @param ... arguments passed to mutate(...) | |
#' @export | |
grouped_mutate <- function(.data, .by, ...) { | |
pre <- groups(.data) | |
if (is.null(pre)) pre <- list() |
This file contains hidden or 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(rCharts) | |
.ymax <- 20 | |
.radius <- 5 | |
a <- Highcharts$new() | |
a$chart(type = "scatter") | |
a$series(list( |
This file contains hidden or 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(knitr) | |
library(mailR) | |
library(XLConnect) | |
rmd_to_html <- function(input, output = paste0(tempfile(), ".html")) { | |
knit2html(input = input, output = output, quiet = T,options="") | |
return(output) | |
} | |
df_to_csv <- function(input, output = paste0(tempfile(), ".csv")) { |
This file contains hidden or 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
<!doctype HTML> | |
<meta charset = 'utf-8'> | |
<html> | |
<head> | |
<script src='http://code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script> | |
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'></script> | |
<script src='http://code.highcharts.com/highcharts-more.js' type='text/javascript'></script> | |
<script src='http://code.highcharts.com/modules/exporting.js' type='text/javascript'></script> | |
This file contains hidden or 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
a <- Highcharts$new() | |
a$chart(type = "spline", backgroundColor = NULL) | |
a$series(data = c(1, 3, 2, 4, 5, 4, 6, 2, 3, 5, NA), dashStyle = "longdash") | |
a$series(data = c(NA, 4, 1, 3, 4, 2, 9, 1, 2, 3, 1), dashStyle = "shortdot") | |
a$legend(symbolWidth = 80) | |
a$set(height = 250) | |
a |
This file contains hidden or 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(rCharts) | |
shinyServer(function(input, output) { | |
output$text <- renderText({ | |
sprintf("The capital of %s is %s.", input$click$country, input$click$capital) | |
}) | |
output$chart <- renderChart({ |
This file contains hidden or 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(Coldbir) | |
a <- cdb(tempfile()) | |
a[] <- mtcars | |
a[, 2012] <- mtcars | |
a[, 2013] <- mtcars | |
a[, c(2012,12)] <- mtcars | |
a[, c(2012,11)] <- mtcars | |
# DEFAULT: a[NULL, .all] |
This file contains hidden or 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
#!/usr/bin/Rscript | |
require(knitr) | |
lf <- commandArgs(trailingOnly = TRUE) | |
if(!length(lf)) | |
lf = list.files(pattern="\\.rmd") | |
for (f in lf) | |
try(knit(f)) | |
md = paste0(sub("\\.[[:alnum:]]*$", "", lf), ".md") |
This file contains hidden or 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
build: | |
Rscript build.r | |
clean: | |
rm -rf *.tex *.tex-e *.bbl *.blg *.aux *.out *.log *.spl plots/ cache/ *.gz\(busy\) *.gz *.pdf |