Skip to content

Instantly share code, notes, and snippets.

View zkamvar's full-sized avatar
🍄
On Sabbatical

Zhian N. Kamvar zkamvar

🍄
On Sabbatical
View GitHub Profile
library("devtools") # with_lib(), install_github()
tmp_lib <- file.path(tempdir(), ".lib")
dir.create(tmp_lib)
cran_pkg <- function(pkg, tmp_lib = tmp_lib){
## upgrade or downgrade a package here
## following example is upgrading to bleeding edge devel version
with_lib(tmp_lib, install.packages(pkg, repos = "http://cran.rstudio.com"))
## but this could also be a downgrade to the CRAN/released version!
@zkamvar
zkamvar / rdevdocker.md
Last active August 29, 2015 14:20
r-devel docker to test poppr

Notes for working with docker to test poppr on R-devel

I recently got an email from Kurt Hornik from CRAN stating that a single line of code was causing poppr to fail in R-devel. Since installing R-devel is a pain on OSX, I decided to use a docker container. Ted Hart has a good blog on it here.

On mac, I followed the instructions to install docker starting here.

I ran this once and have never had to run it again:

@zkamvar
zkamvar / 2015_05_19_git2r.md
Last active December 5, 2015 01:32
Updating forks with git2r

Motivation

I am a contributor to NESCent's Population Genetics in R repository. The idea behind this repository is that people would be able to construct short vignettes for genetic analysis in R that can be displayed on the Population Genetics Info Website. Of course, the submissions would need to be pull requests from other users that would have forked the repository. For beginners, updating a fork is not a simple task. It requires that you fetch the upstream branch and then merge that branch into your head.

One problem: neither the OSX nor Windows GUIs have the ability to synch a fork from upstream, meaning that the contributors would have to know some command line options. This isn't a terrible thing all in all, because OSX has a Terminal app and users can access the shell from the Windows GUI. I recently attempted to test things on a w

@zkamvar
zkamvar / power_mlg.R
Last active August 29, 2015 14:21
Playing with the power law and multilocus genotypes
plot_mlg_stats <- function(x, type = "p", palette = rainbow, ...){
layout(matrix(1:6, nrow = 2))
if (is.list(x)){
minmax <- matrix(numeric(0), nrow = 2, ncol = 8,
dimnames = list(c("min", "max"),
rownames(x[[1]])))
minmax["min", ] <- apply(vapply(x, function(i) apply(i, 1, min), numeric(8)), 1, min)
minmax["max", ] <- apply(vapply(x, function(i) apply(i, 1, max), numeric(8)), 1, max)
pal <- match.fun(palette)
cols <- pal(length(x))
@zkamvar
zkamvar / Makevars
Created July 14, 2015 20:54
My R Makevars file to ensure that I build R packages with openmp
# This file's location is ~/.R/Makevars
# Default variables (no omp support):
# CXX=clang++
# CC=clang
# I followed the instructions at http://hpc.sourceforge.net/ to install gcc 4.9
CC=/usr/local/bin/gcc
CXX=/usr/local/bin/g++
FC=/usr/local/bin/gfortran
F77=/usr/local/bin/gfortran
@zkamvar
zkamvar / resort_microsatellites.R
Created August 6, 2015 15:42
Place microsatellites in the correct order for genind objects.
resort_microsat <- function(x){
# Gather all alleles, convert to numeric, and reorder
alls <- adegenet::alleles(x)
alln <- lapply(alls, as.numeric)
alln <- lapply(alln, order)
# Loop over the names and paste together the locus name and the sorted alleles.
alls <- lapply(names(alls), function(i) paste(i, alls[[i]][ alln[[i]] ], sep = "."))
# Convert to a vector an match the name to the column names of the data matrix.
@zkamvar
zkamvar / znk_snippets.snippets
Last active July 12, 2016 13:04
Custom snippets that I use for Rstudio
# test that skeleton
snippet tt
test_that("${1:stuffworks}", {
${2:skip_on_cran()}
})
# add a header line
snippet hl
#==============================================================================#
${0}
@zkamvar
zkamvar / poppr-check-2015-11-29.md
Created November 29, 2015 21:04
poppr R CMD check with address sanitizer 2015-11-29
@zkamvar
zkamvar / update_fork_git2r.R
Created December 6, 2015 18:56
Script for keeping a fork up to date with git2r
# 2015-12-06 10:55:45 PST ----------------------------------
# This script will allow you to update your fork of the
# NESCent popgenInfo page without having to interact with
# the command line. Note: you do not need to install git
# for this particular script to work, but it is necessary
# to use pull/commit/push through Rstudio.
library("git2r")
# Do this once and then open the Rproject file ------------
# clone(url = "",
We can't make this file beautiful and searchable because it's too large.
"INRA63.167","INRA63.171","INRA63.173","INRA63.175","INRA63.177","INRA63.179","INRA63.181","INRA63.183","INRA63.185","INRA5.137","INRA5.139","INRA5.141","INRA5.143","INRA5.145","INRA5.147","INRA5.149","ETH225.137","ETH225.139","ETH225.141","ETH225.143","ETH225.145","ETH225.147","ETH225.149","ETH225.151","ETH225.153","ETH225.155","ETH225.157","ETH225.159","ILSTS5.182","ILSTS5.184","ILSTS5.186","ILSTS5.190","ILSTS5.194","HEL5.149","HEL5.151","HEL5.153","HEL5.155","HEL5.157","HEL5.159","HEL5.161","HEL5.163","HEL5.165","HEL5.167","HEL5.169","HEL1.101","HEL1.103","HEL1.105","HEL1.107","HEL1.109","HEL1.111","HEL1.113","HEL1.115","HEL1.117","INRA35.102","INRA35.104","INRA35.106","INRA35.108","INRA35.110","INRA35.114","INRA35.120","ETH152.181","ETH152.187","ETH152.191","ETH152.193","ETH152.195","ETH152.197","ETH152.199","ETH152.201","ETH152.203","ETH152.205","ETH152.207","ETH152.209","INRA23.193","INRA23.197","INRA23.199","INRA23.201","INRA23.203","INRA23.205","INRA23.207","INRA23.209","INRA23.211","INRA23.213","INRA