Skip to content

Instantly share code, notes, and snippets.

View gluc's full-sized avatar

Christoph Glur gluc

View GitHub Profile
library(data.tree)
yaml <- "
campus:
south:
label: campussouth
north:
label: campusnorth
"
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)
library(yaml)
yaml <- "
node1:
value: 2
fnct: >
function(x) {
2 * x
@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)
@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 / 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 / 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 / LoadFunctionYaml.R
Last active October 4, 2015 11:36
data.tree YAML function
#requires data.tree 0.2.2
library(data.tree)
library(yaml)
library(stringr)
fileName <- 'jennylind.yaml'
l <- yaml.load_file(fileName)
jl <- as.Node(l)
#this file contains all the functions referred to from the yaml
@gluc
gluc / crossover.R
Last active September 29, 2015 03:06
Genetics Crossover
library(data.tree)
CreateCrossoverRandomTree <- function(n, treeId) {
tree <- CreateRandomTree(n)
tree$Set(treeId = treeId)
tree$Set(id = 1:tree$totalCount)
return (tree)
}
@gluc
gluc / app.R
Last active August 27, 2024 22:35
Shiny CRUD
library(shiny)
library(shinyjs)
# Get table metadata. For now, just the fields
# Further development: also define field types
# and create inputs generically
GetTableMetadata <- function() {
fields <- c(id = "Id",