Skip to content

Instantly share code, notes, and snippets.

@renkun-ken
renkun-ken / r-supportive-members
Last active August 29, 2015 14:06
Where do R's supportive members mainly come from?
library(pipeR) # https://github.com/renkun-ken/pipeR
library(rlist) # https://github.com/renkun-ken/rlist
library(rvest) # https://github.com/hadley/rvest
library(stringr) # https://github.com/hadley/stringr
# please ensure rvest is the latest dev version
Pipe("http://www.r-project.org/foundation/memberlist.html")$
html()$ # use xpath to scrape the name list
html_nodes(xpath = "//table[2]//td//text() | //table[3]//td//text()")$
html_text(trim = TRUE)$
@renkun-ken
renkun-ken / README.md
Last active August 29, 2015 14:06
A Pipe version with recommended practice

A Pipe version of Zev Ross.

An alternative version of timelyportfolio's and smbache's.

If you are not familiar with pipeR, you can read the still-in-progress pipeR tutorial. The best practices of pipeR's Pipe():

  • Keep side effects as small as possible, use it only when necessary.
  • Separate Pipes into concentrated pieces.
  • Don't avoid necessary intermediate variables.
@renkun-ken
renkun-ken / pipeR.R
Last active August 29, 2015 14:08
simpler pipeR_world
# inspired by the amazing idea of hoxo_m
# see http://qiita.com/hoxo_m/items/3fd3d2520fa014a248cb
# shocked even if you don't understand Japanese!
pipes <- function(expr) {
expr <- substitute(expr)
pipe_expr <- if(expr == "{") {
Reduce(function(pl, p) as.call(list(quote(`%>>%`), pl, p)), expr[-1L])
} else expr
eval(pipe_expr, envir = parent.frame())
@renkun-ken
renkun-ken / demo.Rmd
Last active August 29, 2015 14:19
formattable (bootstrap glyphicons + bar)
```{r,results='hide',echo=FALSE,message=FALSE}
library(formattable)
df <- data.frame(
id = 1:10,
name = c("Bob", "Ashley", "James", "David", "Jenny",
"Hans", "Leo", "John", "Emily", "Lee"),
age = c(28, 27, 30, 28, 29, 29, 27, 27, 31, 30),
grade = c("C", "A", "A", "C", "B", "B", "B", "A", "C", "C"),
test1_score = c(8.9, 9.5, 9.6, 8.9, 9.1, 9.3, 9.3, 9.9, 8.5, 8.6),
test2_score = c(9.1, 9.1, 9.2, 9.1, 8.9, 8.5, 9.2, 9.3, 9.1, 8.8),
@renkun-ken
renkun-ken / options.R
Created January 13, 2016 04:56
option-tools
payoff <- function(f, class = NULL, type = NULL, ...) {
structure(f, class = c(class, "payoff", "function"),
type = type, args = list(...))
}
Call <- function(K, N = 1, X = 0, C = 0) {
payoff(function(x) N * (pmax(x - K, 0) - X) - abs(N) * C,
class = "option", type = "Call", K = K, N = N, X = X, C = C)
}
@renkun-ken
renkun-ken / iris-formattable.R
Created January 24, 2016 16:03
iris-formattable
library(shiny)
library(formattable)
data <- iris
species <- levels(data$Species)
ui <- shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarPanel(checkboxGroupInput("species", label = "species", choices = species,
selected = species),
@renkun-ken
renkun-ken / demo.R
Created June 20, 2016 04:52
formattable: color bar + color text
library(formattable)
data <- data.frame(id = 1:10, x = rbinom(10, 100, 0.8))
formattable(data, list(x = formatter("span",
style = x ~ style(
display = "inline-block",
direction = "rtl",
"border-radius" = "4px",
"padding-right" = "2px",
@renkun-ken
renkun-ken / product-info.csv
Created July 25, 2016 13:18
Demo data of products
id name type class released
T01 SupCar toy vehicle yes
T02 SupPlane toy vehicle no
M01 JeepX model vehicle yes
M02 AircraftX model vehicle yes
M03 Runner model people yes
M04 Dancer model people no
@renkun-ken
renkun-ken / active-binding.R
Last active August 25, 2016 12:07
hide-source
e <- new.env()
makeActiveBinding("private_f", function(x) {
if (missing(x)) {
NULL
} else {
sum <- 0
for (i in 1:x) {
sum <- sum + i
}
@renkun-ken
renkun-ken / .tmux.conf
Created July 3, 2018 15:36
My tmux config
# Global options
## No delay for escape key press
set -sg escape-time 0
## Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on
## don't rename windows automatically
set-option -g allow-rename off