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
if (interactive()) { | |
local({ | |
pid <- Sys.getpid() | |
tempdir <- tempdir(check = TRUE) | |
dir <- normalizePath(file.path(".vscode", "vscode-R"), mustWork = FALSE) | |
dir_session <- file.path(dir, pid) | |
if (dir.create(dir_session, showWarnings = FALSE, recursive = TRUE) || dir.exists(dir_session)) { | |
reg.finalizer(.GlobalEnv, function(e) { | |
unlink(dir_session, recursive = TRUE, force = TRUE) | |
}, onexit = TRUE) |
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(data.table) | |
dir <- "~/output/sim" | |
dir.create(dir, showWarnings = FALSE, recursive = TRUE) | |
params <- expand.grid( | |
n = c(100, 1000, 10000), | |
mean = c(0.1, 0.2, 0.3), | |
sd = c(0.5, 1, 1.5)) |
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
# 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 |
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
e <- new.env() | |
makeActiveBinding("private_f", function(x) { | |
if (missing(x)) { | |
NULL | |
} else { | |
sum <- 0 | |
for (i in 1:x) { | |
sum <- sum + 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
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 |
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(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", |
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(formattable) | |
data <- iris | |
species <- levels(data$Species) | |
ui <- shinyUI(fluidPage( | |
titlePanel("Old Faithful Geyser Data"), | |
sidebarPanel(checkboxGroupInput("species", label = "species", choices = species, | |
selected = species), |
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
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) | |
} |
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
```{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), |
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
# 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()) |
NewerOlder