Skip to content

Instantly share code, notes, and snippets.

@pr130
pr130 / ggplot_geom_line_na.R
Created February 19, 2021 10:50
ggplot geom_line NA behaviour
library(tidyverse)
data <- readr::read_csv("https://raw.githubusercontent.com/friep/correlaid-utils/main/correlaid-analytics/data/all_daily.csv")
# clean out facebook outliers /errors
data <- data %>%
filter(!(platform == "facebook" & date > "2020-01-01" & n < 10))
# geom line connects the missing pieces but i don't want that!!!
data %>%
ggplot(aes(x = date, y = n, color = platform))+
@pr130
pr130 / clean_dkb_data.Rmd
Created October 10, 2020 13:37
Clean csvs exported from DKB online banking
---
title: "DKB Export Cleanup"
author: "Frie"
date: "10/10/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(purrr)
@pr130
pr130 / pycharacterlist_to_rows.R
Created September 1, 2020 15:05
Python character list to rows
library(dplyr)
library(tibble)
library(stringr)
library(tidyr)
py_list_vec <- c('["foo", "bar", "baz"]', '["test1", "tst2"]', '["a", "b", "c", "d", "e"]')
df <- tibble::tibble(id = c(1, 2, 3), x = py_list_vec)
df %>%
dplyr::mutate(x = stringr::str_replace(x, '\\[', "")) %>%
dplyr::mutate(x = stringr::str_replace(x, '\\]', "")) %>%
@pr130
pr130 / docker-compose.yml
Last active February 14, 2020 15:42
docker-compose codimd
# Using version 3 to provide play-with-docker badge
# You can change to version 2 without breaking.
#version: '2'
version: '3'
services:
database:
# Don't upgrade PostgreSQL by simply changing the version number
# You need to migrate the Database to the new PostgreSQL version
image: postgres:9.6-alpine
#mem_limit: 256mb # version 2 only
@pr130
pr130 / find_similar_words.R
Created September 6, 2019 19:01
Find words that are similar in following rows.
library(stringr)
library(dplyr)
library(stringdist)
df <- tibble(word = c("Agrilus pilosivittatus",
"Agrilus pilosovittatus",
"foo",
"bar",
"baz",
"something else",

Keybase proof

I hereby claim:

  • I am friep on github.
  • I am friep (https://keybase.io/friep) on keybase.
  • I have a public key ASAIEdvRrwkKfZoqisFOZfo4I4-QtL3lA8Kd2pE0vDAFLwo

To claim this, I am signing this object:

@pr130
pr130 / are_named_lists_subset_of_other_list.R
Created March 14, 2019 16:19
R functions that allow to check whether named lists are a subset of a bigger list.
# written as part of the sealr package: github.com/jandix/sealr
library(purrr)
#'
#' This function checks that all claims passed in the \code{claims} argument of the jwt function are
#' correct.
#' @param token JWT extracted with jose::jwt_decode_hmac.
#' @param claims named list of claims to check in the JWT. Claims can be nested.
#' @return TRUE if the all claims are present in the JWT, FALSE if not.
@pr130
pr130 / nested_error_handling
Created July 2, 2018 21:08
Trying to exit a cascade of functions in R
# nested error handling
third_level <- function(c, d){
print(paste0("c ", c, " d ", d))
if (c > 2){
stop("Invalid value for c. Exiting third level.")
}
else {
return(c + d)
}