Skip to content

Instantly share code, notes, and snippets.

Floo0 rentrop

Block or report user

Report or block rentrop

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rentrop
rentrop / waterfall.R
Created Dec 11, 2017
ggplot waterfall chart
View waterfall.R
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)],
@rentrop
rentrop / compact_print_lmrob_summary.R
Last active Mar 25, 2017
Compact print for summary.lmrob - this does not print all row-indices of all outliers
View compact_print_lmrob_summary.R
# 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])
@rentrop
rentrop / graphql-example.R
Last active Jun 16, 2018
Querying GraphQL with R using httr
View graphql-example.R
# 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,
@rentrop
rentrop / parse_nested.R
Last active Oct 30, 2017
Parse nested xml_children in R with rvest/xml2
View parse_nested.R
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(),
@rentrop
rentrop / gg_qq.r
Last active Mar 22, 2018
This function plots a QQplot as ggplot in R - Parts of the code copied from `car:::qqPlot`
View gg_qq.r
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, ...))
You can’t perform that action at this time.