Skip to content

Instantly share code, notes, and snippets.

View muschellij2's full-sized avatar

John Muschelli muschellij2

View GitHub Profile
@muschellij2
muschellij2 / any_redirect.R
Created February 16, 2018 22:00
Checks for any redirection in a `httr` call
library(httr)
any_redirect = function(x) {
hdrs = x$all_headers
statuses = sapply(hdrs, `[[`, "status")
res = lapply(statuses, httr::http_status)
res = sapply(res, `[[`, "category")
"redirection" %in% tolower(res)
}
res300 = GET("http://httpbin.org/status/300")
@muschellij2
muschellij2 / example_ggplot2_pipe.R
Created February 15, 2018 21:41
ggplot2 with apipe
library(ggplot2)
library(dplyr)
geom = function(gplot, type, ...) {
func_name = paste0("geom_", type)
args = list(...)
g = do.call(func_name, args = args)
gplot + g
}
# NAs break the line. Use na.rm = T to suppress the warning message
##############################
#
##############################
rm(list=ls())
library(matrixStats)
library(RNifti)
ensure_Nifti = function(x) {
if (is.list(x)) {
x = lapply(x, ensure_Nifti)
[1] "1.1.383"
$R
[1] "/usr/local/bin/R"
$pdflatex
[1] "/Library/TeX/texbin/pdflatex"
$bibtex
[1] "/Library/TeX/texbin/bibtex"
@muschellij2
muschellij2 / make_citation.R
Created October 12, 2017 17:55
Making a CITATION file for R package from bibtex entry
library(bibtex)
x = "@article{shou2013quantifying,
title={Quantifying the reliability of image replication studies: the image intraclass correlation coefficient (I2C2)},
author={Shou, H and Eloyan, A and Lee, S and Zipunnikov, V and Crainiceanu, AN and Nebel, MB and Caffo, B and Lindquist, MA and Crainiceanu, CM},
journal={Cognitive, Affective, & Behavioral Neuroscience},
volume={13},
number={4},
pages={714--724},
year={2013},
publisher={Springer}
@muschellij2
muschellij2 / date_match_example.R
Created October 12, 2017 05:40
Fuzzy Matching to data sets based on a Date
library(lubridate)
rdate <- function(size,
min = paste0(format(Sys.Date(), '%Y'), '-01-01'),
max = paste0(format(Sys.Date(), '%Y'), '-12-31'),
sort = TRUE) {
dates <- sample(
seq(as.Date(min), as.Date(max), by = "day"),
size = size, replace = TRUE)
@muschellij2
muschellij2 / all_system_requirements.R
Created October 12, 2017 05:38
Parse SystemRequirements fields from R Packages
rm(list=ls())
# devtools::install_github("metacran/crandb")
library(crandb)
# pack = package("fftw")
# sysreq = pack$SystemRequirements
library(magrittr)
DB <- function(api, head = 1e6, tail = head) {
@muschellij2
muschellij2 / all_examples.R
Created October 12, 2017 05:36
Get All Examples from an R Packag
all_examples = function(path = ".", commentDontrun = FALSE) {
# list all the Rd files
files = list.files(
path = file.path(path, "man"),
pattern = "Rd$",
recursive = FALSE,
full.names = TRUE)
tfiles = sapply(files, function(x) {
tfile = tempfile(fileext = ".R")
# turn to examples
@muschellij2
muschellij2 / check_script_antsrcore.sh
Created June 19, 2017 14:26
ANTsRCore Check Script
source ~/.R/Makevars
export CXX=clang++
export CC=clang
cd ..
travis_wait 100 R CMD build ANTsRCore ${R_BUILD_ARGS}
PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
if [[ ${#TRAVIS_TAG} -eq 0 ]];
then
travis_wait 100 R CMD check ${R_CHECK_ARGS} "${PKG_FILE_NAME}" --no-manual;
fi # --as-cran
@muschellij2
muschellij2 / current_antsr_travis.sh
Last active July 15, 2019 18:00
Current Links to ANTsR for Travis
export RGL_USE_NULL=TRUE
cmake_version="3.11"
ants_user=stnava
wget -O antsr_travis.sh http://bit.ly/antsr_travis_sh
chmod +x antsr_travis.sh
source ./antsr_travis.sh
rm antsr_travis.sh