Skip to content

Instantly share code, notes, and snippets.

View brandmaier's full-sized avatar

Andreas Brandmaier brandmaier

View GitHub Profile
@brandmaier
brandmaier / position_jitter_gaussian.R
Created December 13, 2017 20:00
A ggplot jitter function based on Gaussian noise: position_jitter_gaussian()
#
# provides function position_jitter_gaussian() for ggplot2
#
# Use parameters width and height for scaling of dispersion
#
# Example:
#df <- data.frame(
# x = rep(c(1,3,2,5,5,5,5),5),
# y = rep(c(1,3,2,5,5,5,5),5)
#)
@brandmaier
brandmaier / semtree-hexsticker.R
Created November 28, 2019 10:37
hex sticker for semtree package
# define colors
dark.green<-"#48631A"
light.green<-"#87B13F"
# hex sticker library
library(hexSticker)
# public domain image source:
# https://publicdomainvectors.org/en/free-clipart/Vector-clip-art-of-oaktree-with-wide-treetop/24731.html
imgurl<-"https://publicdomainvectors.org/photos/tree-oak400px.png"
@brandmaier
brandmaier / obleser-pokemon.R
Created June 2, 2020 06:31
Create histogram from Pokémon puzzle challenge
library(rtweet)
library(stringr)
# get last 100 tweets
tweets <- search_tweets("jonasobleser",n = 100)
# extract numbers with one or more digits
numbers <- sapply(tweets$text,
function(x) {
as.numeric(str_extract(x, "([0-9]+)"))
})
@brandmaier
brandmaier / gist:79b732c6a35244f0cb1ea12fea063247
Created August 11, 2021 14:52
Fedora Linux Dockerfile for BGGM
#
# This is a Dockerfile to create a Fedora Linux environment
# with the latest version of BGGM from Donald's github repository
#
FROM rhub/fedora-clang-devel
ARG BUILD_DATE=2021-07-25
RUN dnf install R -y
RUN sudo dnf install 'dnf-command(copr)' -y
RUN sudo dnf copr enable iucar/cran -y
RUN sudo dnf install R-CoprManager -y
@brandmaier
brandmaier / gist:5385ccd7e672f1bbf0025154c1f9aa31
Created May 14, 2024 10:38
R: Create sorted numeric IDs in a datafile with alphanumeric IDs
# we simulate a data set with an alphanumeric ID column and some
# observed values x
# The goal is to give out new participant IDs with consecutive numbers
# starting from 1 (while maintaining the original order)
dat <- data.frame(id=c("P1","P1","P1","second","second","second","3rd","no4","no4"),
x=rnorm(9))
# convert IDs to a factor and then use position of factor level as new ID
# /!\ this yields ID that are according to alphanumeric sorting of original IDs
dat$numeric_id <- as.numeric(factor(dat$id))
@brandmaier
brandmaier / test-browser.R
Created June 6, 2024 12:56
test whether developers forgot a browser() debug statement in their R package code
#'
#' This is a test using the `testthat` package for R
#'
#' @title Test whether developers forgot a browser() debug statement in their R package code
#'
#' @description
#' Test goal: Check all functions of the encompassing R package
#' for whether developers forgot a browser()-statement
#' while debugging.
#'