Skip to content

Instantly share code, notes, and snippets.

View rmflight's full-sized avatar

Robert M Flight rmflight

View GitHub Profile
@rmflight
rmflight / example_recurse.R
Created December 9, 2015 15:59
reproducible example to get number of counts of function runs in semi-recursive
# function where first calls another function, that in turn calls the first,
# but does so in a way that the second is not called again. I want to test
# how many times f1 and f2 get called under different conditions
f1 <- function(use_f2 = FALSE){
if (use_f2) {
f2()
}
}
@rmflight
rmflight / testing_praise.md
Last active August 29, 2015 14:26
optional praises to add to testthat

Below are possible additions to add to the praise that testthat randomly provides if all test pass successfully. I am listing the github username and the praise phrase. The idea is that eventually a pull request would be put together so that @hadley can include them in testthat. The current praises are listed here

@rmflight: It didn't blow up!
@jennybc: Your code is a wonderland.
@rmflight: All conditions normal.
@rmflight: You didn't expect an error, did you?
@rmflight: All systems go for launch!
@rmflight: You're pretty good at this testing thing.
@rmflight: Superstar!
@rmflight
rmflight / character_similarity.R
Created June 11, 2015 16:25
character_similarity R vs cpp
character_similarity_R <- function(character_list, similarity_type = "overlap"){
use_list <- names(character_list)
n_list <- length(use_list)
all_comparisons <- expand.grid(seq(1, n_list), seq(1, n_list))
all_comparisons <- all_comparisons[(all_comparisons[,2] > all_comparisons[,1]), ]
all_comparisons <- as.matrix(all_comparisons)
calc_similarity <- function(x){
@rmflight
rmflight / adv-r.md
Last active June 7, 2017 04:07
compiling @hadley books

In the shell:

git clone https://github.com/hadley/adv-r.git
gem install jekyll mime-types

In R:

@rmflight
rmflight / binned_function.R
Last active August 29, 2015 14:09
robust version of function along genome bins
#' calculate binned values
#'
#' given a set of genomic bins and an RLE-list object, return value
#'
#' Adapted from documentation of \code{tileGenome}
#'
#' @param bins a \code{GRanges} object representing genomic bins
#' @param numvar a named \code{RleList} object representing numerical variable along the genome
#' @param binfun character string of the function to apply
#' @param mcolname the name of the metadata column containing the binned value of the object
@rmflight
rmflight / updatePackagesScript.R
Last active July 7, 2016 19:18
updating full set of installed packages in R
# list of github installed packages
#gitPackages <- list(c("devtools", "hadley"),
# c("samatha", "DASpringate"),
# c("twitteR", "geoffjentry"))
# Other specific things
# list of local packages
localPackages <- c("~/Projects/work/rmfNotifier")
@rmflight
rmflight / post-commit
Last active March 29, 2024 19:43
useful commit hooks for R package dev
#!/path/2/Rscript
# License: CC0 (just be nice and point others to where you got this)
# Author: Robert M Flight <rflight79@gmail.com>, github.com/rmflight
#
# This is a post-commit hook that after a successful commit subsequently increments the package version in DESCRIPTION
# and commits that. Analogous to the pre-commit at https://gist.github.com/rmflight/8863882, but useful if you only have
# good reasons for not doing it on the pre-commit.
#
# To install it, simply copy this into the ".git/hooks/post-commit" file of your git repo, change /path/2/Rscript, and make
@rmflight
rmflight / go2list.R
Last active December 31, 2015 18:22
temporary workaround for getting categoryCompare go2list associations
# assumes that a ccCompareResult object has been generated from a ccEnrichResult, eg ccResults from the vignette
# note that the $BP is to access a single ccCompareResult from a collection, these are generally BP, MF, CC, KEGG, etc
library(graph)
tmpGraph <- mainGraph(ccResults$BP)
tmpData <- nodeData(tmpGraph, , "listMembership")
go2list <- data.frame(goid = names(tmpData), listMembership = unlist(tmpData), stringsAsFactors=FALSE)
@rmflight
rmflight / testTextOut.Rmd
Last active December 28, 2015 05:49
testing knitr formatting for text output
```{r t1}
crud <- "alksdjflkajsdflkajsdf"
```
Here is some text for context
```{r t2, echo=FALSE, results='asis'}
cat(paste("```",crud,"```", sep="\n"))
```