Skip to content

Instantly share code, notes, and snippets.

View gluc's full-sized avatar

Christoph Glur gluc

View GitHub Profile
@gluc
gluc / app.R
Last active October 11, 2015 03:18
Shiny Generic In Memory
#CRUD for multiple tables
library(shiny)
library(shinyjs)
# Get table metadata. For now, just the fields
# Further development: also define field types
# and create inputs generically
GetTableMetadata <- function() {
@gluc
gluc / example.rmd
Created October 19, 2015 18:11
Problem Pandoc / Mermaid
---
title: "Untitled"
author: "cg"
date: "Monday, October 19, 2015"
output: html_document
---
```{r}
@gluc
gluc / profile.R
Last active January 16, 2016 07:54
using data.tree to analyse Rprof files
tmp <- tempfile(fileext = ".log")
x <- runif(10e5)
f <- function(x) c(mean(x), median(x), sd(x))
f2 <- function(x) {
c(sum(x) / length(x),
median.default(x),
sqrt(sum((x - sum(x) / length(x))^2L) / (length(x) - 1L)))
}
Rprof(tmp, interval = 0.01)
@gluc
gluc / tree-plotting.R
Created April 28, 2016 18:31
How to plot with data.tree to a pdf file?
#How to plot data.tree to PDF?
#This was tested with data.tree 0.3.6
#Various options
library(data.tree)
data(acme)
# 1. ape package
library(ape)
library(data.tree)
library(yaml)
yaml <- "
node1:
value: 2
fnct: >
function(x) {
2 * x
library(yaml)
library(data.tree)
yaml <- "
functions:
currbalfun: |
function(node) {
Aggregate(deal, 'currbal', function(bal) sum(bal, na.rm = TRUE))
}
TC_1:
library(data.tree)
yaml <- "
campus:
south:
label: campussouth
north:
label: campusnorth
"
library(data.tree)
yaml <- "
campus:
south:
label: campussouth
north:
label: campusnorth
"
@gluc
gluc / dohts.R
Last active August 26, 2016 23:03
library(data.tree)
library(xts)
f <- read.csv("https://gist.githubusercontent.com/gluc/3969bcfb2ddce61d8bdec2f52c133674/raw/16b577a6842492153db8e95ede0062a6187e60ab/hts-data.csv", stringsAsFactors = FALSE)
# construct tree
# ==============
# you may chose a different hierarchy order
dfs <- data.frame(pathString = paste("rt", df$u_loc, df$u_code, df$c_code, df$citizenship, df$grade, sep = "/"), stringsAsFactors = FALSE)
@gluc
gluc / DiagrammeR.R
Created December 17, 2016 16:03
Newest version of DiagrammeR
nodes <- structure(list(id = 1:11, style = c("", "", "", "", "", "", "",
"", "", "", ""), shape = c("", "", "egg", "egg", "", "egg", "egg",
"", "egg", "egg", "egg"), fillcolor = c("", "Thistle", "", "",
"", "", "", "LightBlue", "LightBlue", "LightBlue", "LightBlue"
), fontname = c("", "", "", "", "", "", "", "", "", "", ""),
tooltip = c("- name: Acme Inc.", "This is the accounting department",
"- cost: 1e+06\n- p: 0.5", "- cost: 5e+05\n- p: 0.75", "- name: Research",
"- cost: 2e+06\n- p: 0.25", "- cost: 750000\n- p: 0.9", "- name: IT",
"- cost: 4e+05\n- p: 0.2", "- cost: 250000\n- p: 0.05", "- cost: 50000\n- p: 1"
), fontcolor = c("", "Firebrick", "", "", "", "", "", "",