Skip to content

Instantly share code, notes, and snippets.

@anfederico
anfederico / update.R
Last active April 26, 2020 13:48
Must have packages after every update
# CRAN
pkgs <- c("devtools",
"ggplot2",
"ggforce",
"tidyverse",
"R6",
"stats",
"stringr",
"scales",
"rlang",
@anfederico
anfederico / sigxcel.R
Created June 20, 2019 14:08
Write vectors of unequal sizes to excel
library(openxlsx)
library(magrittr)
library(plyr)
wb.init <- function() {
wb <- openxlsx::createWorkbook()
return(wb)
}
wb.add.sheet <- function(wb, sheet="1", signatures) {
@anfederico
anfederico / ggvenn.R
Last active May 23, 2019 01:28
Venn diagram written in ggplot
library(ggplot2)
library(ggforce)
ggvenn <- function(a, b, ga, gb, title="") {
# Calculate area
x.a <- length(a)
x.b <- length(b)
x.u <- length(intersect(a, b))
@anfederico
anfederico / format_str.R
Created April 25, 2019 03:12
Python style string formatting in R
example <- "An example {1} where adding {2} and {2} and {3}"
val.1 <- "Value 1"
val.2 <- "Value 2"
val.3 <- "Value 3"
format_str <- function(string, ...) {
args <- list(...)
for (i in 1:length(args)) {
pattern <- paste("\\{", i, "}", sep="")
@anfederico
anfederico / pvector.R
Created April 24, 2019 03:02
A push/pop capable vector in R
library(R6)
pvector <- R6Class("pvector", list(
values = NULL,
initialize = function(values=c()) {
self$values <- values
},
pop = function() {
if (length(self$values) > 0) {
popped.value <- self$values[1]
@anfederico
anfederico / .gitignore
Created March 21, 2019 23:51
Personal gitignore file for Python/R projects on Mac OSX
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
@anfederico
anfederico / assign.R
Last active July 12, 2018 17:34
Alternative version of ASSIGN heatmap plot
require(Biobase)
require(RColorBrewer)
require(plotly)
# Fake Data
set.seed(124)
samples = paste("S", (1:50), sep="")
genes = paste("G", (1:200), sep="")
row_hist1 = runif(50, min=0, max=1)
row_hist2 = runif(50, min=0.9, max=1)
@anfederico
anfederico / dust.py
Created January 22, 2018 01:57
Get rid of dust on your Binance account
# pip install python-binance
from binance.client import Client
client = Client(api_key, api_secret)
DUST = 0.001 # BTC
account = client.get_account()
prices = client.get_all_tickers()