Skip to content

Instantly share code, notes, and snippets.

View rentrop's full-sized avatar

Floo0 rentrop

View GitHub Profile
@rentrop
rentrop / graphql-example.R
Last active February 7, 2024 12:33
Querying GraphQL with R using httr
# 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 / gg_qq.r
Last active December 3, 2023 06:01
This function plots a QQplot as ggplot in R - Parts of the code copied from `car:::qqPlot`
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, ...))
@rentrop
rentrop / waterfall.R
Created December 11, 2017 17:48
ggplot waterfall chart
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 / parse_nested.R
Last active October 30, 2017 21:53
Parse nested xml_children in R with rvest/xml2
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 / compact_print_lmrob_summary.R
Last active March 25, 2017 00:53
Compact print for summary.lmrob - this does not print all row-indices of all outliers
# 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])