Skip to content

Instantly share code, notes, and snippets.

View yonicd's full-sized avatar

yonicd

View GitHub Profile
@yonicd
yonicd / scales2df
Created July 13, 2017 20:33
create data.frame of hierarchy structure of scales function call in ggplot2 and ggextensions
library(ggraph)
library(dplyr)
library(d3Tree)
scales2df<-function(pkg){
d<-ls(name = sprintf('package:%s',pkg),pattern = '^scale_(.*?)_(.*?)$')
d1<-sapply(d,function(x){grep('_scale|scale_',as.list(body(x)),value=TRUE)})
d.fun<-sapply(d1,function(a) gsub('sc <- ','',gsub('\\((.*?)$','',a)))
@yonicd
yonicd / annotation-ticks.R
Created July 14, 2017 19:53
minor tick marks ggproto layer for log,log10, identity scales on independent sides
#' @title Annotation: tick marks
#' @description This annotation adds tick marks to an axis
#' @export
#' @inheritParams ggplot2::annotation_logticks
#' @param ticks_per_base integer, number of minor ticks between each pair of major ticks, Default: base-1
#' @param delog boolean, if an idenity transformation is needed use set to TRUE, Default: FALSE
#' @examples
#' library(ggplot2)
#' library(grid)
#'
@yonicd
yonicd / github_traffic.R
Last active October 3, 2017 02:11
Function to scrape github to combine your traffic across repositories into one plot
library(RSelenium)
library(XML)
library(ggplot2)
library(reshape2)
library(plyr)
library(dplyr)
gh_user <- '<your github login name>'
gh_pass <- '<your github login password>'
@yonicd
yonicd / .block
Last active January 6, 2018 03:15 — forked from timelyportfolio/.block
alternate version of market quilt
license: mit
height: 600
@yonicd
yonicd / remotes_patch.R
Last active February 23, 2018 13:57
install R packages from github and keep the source install file
remotes_patch <- function(destdir=getwd()){
#patch install_remote
install_remote_keep_source <- remotes:::install_remote
install_remote_body <- body(install_remote_keep_source)
install_remote_body[[6]] <- quote(on.exit({
l <- list(...)
devtools::build(source,path = eval(enquote(l$destdir)))
unlink(source, recursive = TRUE)
}, add = TRUE))
@yonicd
yonicd / burrow.R
Last active April 19, 2018 02:14
traversing in nested R lists
burrow_find <- function(x,parent,regex = FALSE){
if(grepl('(\\[|\\])',parent)){
nx <- as.numeric(gsub('(\\[|\\])','',parent))
}else{
if(regex){
nx <- grep(parent,names(x))
@yonicd
yonicd / testthat_snippet.R
Last active May 17, 2018 12:44
testthat snippets + rsam addin
# dummy functions ----
f <- function() {
testthat::expect_is(data.frame(),'data.frame')
}
f1 <- function() {
testthat::expect_is(data.frame(),'list')
}
@yonicd
yonicd / alm.md
Last active September 29, 2018 20:14
recurrsive version of `purrr::discard`

Install and load alm

install_github("ropensci/alm")
library("alm")
@yonicd
yonicd / toddleR.R
Created January 20, 2019 13:46
toddler in chief analysis
library(rvest)
library(patchwork)
tweet_threading <- function(tw){
last_found <- FALSE
while(!last_found){
nr <- nrow(tw)
last_found <- is.na(tw$reply_to_status_id[nr])