Skip to content

Instantly share code, notes, and snippets.

Avatar

yonicd

View GitHub Profile
@yonicd
yonicd / alm.md
Last active Sep 29, 2018
recurrsive version of `purrr::discard`
View alm.md

Install and load alm

install_github("ropensci/alm")
library("alm")
@yonicd
yonicd / testthat_snippet.R
Last active May 17, 2018
testthat snippets + rsam addin
View testthat_snippet.R
# dummy functions ----
f <- function() {
testthat::expect_is(data.frame(),'data.frame')
}
f1 <- function() {
testthat::expect_is(data.frame(),'list')
}
@yonicd
yonicd / burrow.R
Last active Apr 19, 2018
traversing in nested R lists
View burrow.R
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 / remotes_patch.R
Last active Feb 23, 2018
install R packages from github and keep the source install file
View remotes_patch.R
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 / .block
Last active Jan 6, 2018 — forked from timelyportfolio/.block
alternate version of market quilt
View .block
license: mit
height: 600
@yonicd
yonicd / github_traffic.R
Last active Oct 3, 2017
Function to scrape github to combine your traffic across repositories into one plot
View github_traffic.R
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 / annotation-ticks.R
Created Jul 14, 2017
minor tick marks ggproto layer for log,log10, identity scales on independent sides
View annotation-ticks.R
#' @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 / scales2df
Created Jul 13, 2017
create data.frame of hierarchy structure of scales function call in ggplot2 and ggextensions
View scales2df
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 / selectizegrep
Last active Jun 24, 2017
script to run selectize with grep functionality and clean up the created searches from the option list
View selectizegrep
library(shiny)
shinyApp(
ui = fluidPage(
selectizeInput(inputId = "variable",
label = "Variable:",
choices = split(names(iris),gsub('[_.]',' ',names(iris))),
options=list(multiple=TRUE,create = TRUE)),
checkboxGroupInput(inputId = 'grep',label = 'regex options',
choices = c('Enable'='enbl',
You can’t perform that action at this time.