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
require(tidyverse) | |
tibble( | |
label = c("alt", "bridge1", "bridge2", "bridge3", "bridge4"), | |
value = c(10, 5, -2, 3, 7) | |
) %>% | |
mutate( | |
end = cumsum(value), | |
start = dplyr::lag(end, default = 0), | |
col = c("neg", "pos", "total")[c(3, (value[-1]>0)+1)], |
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
# By default print.summary.lmrob shows all outlier-rowindices. | |
# This sometimes is way too much information, | |
# especially data sets with lots of outliers. | |
# This function just removes the observations from the print output | |
compact_print_lmrob_summary <- function(...){ | |
out <- capture.output(...) | |
observations_ind <- grep("observations c\\(", out) | |
# Remove numbers of observations | |
out[observations_ind] <- sub("observations c\\(.*", "observations", out[observations_ind]) |
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
# Assuming the following GraphQL: https://github.com/calebmer/postgraphql/tree/master/examples/forum | |
# Deploy to AWS via https://github.com/rentrop/serverless-postgraphql | |
require(httr) | |
require(jsonlite) | |
# Define helper function -------------------------------------------------- | |
url <- "https://your-endpoint/graphql" | |
GQL <- function(query, |
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
parse_nested <- function(x, prefix = ''){ | |
kids = x %>% xml_children() | |
ind = which(sapply(kids, xml_length) != 0) | |
if(!length(ind)){ | |
return(setNames(kids %>% xml_text(), | |
paste0(prefix,kids %>% xml_name()))) | |
} | |
nested = parse_nested(kids[ind], | |
prefix = paste0(prefix, kids[ind] %>% xml_name(), "_")) | |
unnested = setNames(kids[-ind] %>% xml_text(), |
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
gg_qq <- function(x, distribution = "norm", ..., line.estimate = NULL, conf = 0.95, | |
labels = names(x)){ | |
q.function <- eval(parse(text = paste0("q", distribution))) | |
d.function <- eval(parse(text = paste0("d", distribution))) | |
x <- na.omit(x) | |
ord <- order(x) | |
n <- length(x) | |
P <- ppoints(length(x)) | |
df <- data.frame(ord.x = x[ord], z = q.function(P, ...)) |