Skip to content

Instantly share code, notes, and snippets.

View cfhammill's full-sized avatar

Chris Hammill cfhammill

View GitHub Profile
@cfhammill
cfhammill / inla-shell.nix
Created November 21, 2019 21:46
Nix-shell comlete with INLA
{ pkgs ? import <nixpkgs> {} }:
let
inlaDeps = with pkgs.rPackages;
[ Matrix
sp
Deriv
devtools
doParallel
fields
@cfhammill
cfhammill / shell.nix
Created August 15, 2019 11:20
A simple nix environment for R analyses. Copy to a folder where you'd like to run an analysis and run `nix-shell`
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
buildInputs = [ git emacs ] ++
(with rPackages;
[
R
ggplot2
@cfhammill
cfhammill / unpack.hs
Last active November 25, 2018 21:33
Unpacking applicative records
import Data.Vinyl.TypeLevel
import Data.Vinyl
import Data.Vinyl.Functor
import Control.Applicative (liftA2)
type family MapTyCon m xs where
MapTyCon m '[] = '[]
MapTyCon m (x ': xs) = m x ': MapTyCon m xs
type family MapTyDeCon (m :: * -> *) (xs :: [*]) where
@cfhammill
cfhammill / funflow-neuro-example.hs
Last active November 16, 2018 14:44
An example funflow pipeline to run a neuroimaging tool
{-# LANGUAGE Arrows
, OverloadedStrings, QuasiQuotes, ScopedTypeVariables
, TemplateHaskell
#-}
import Control.Arrow ((>>>), returnA, (&&&), (***))
import Control.Exception (Exception (..))
import Data.List (intercalate)
import Data.List.NonEmpty (NonEmpty(..))
import Data.Text as T hiding (intercalate, head)
@cfhammill
cfhammill / vau.hs
Last active November 10, 2018 15:52
Fexpr interpreter in haskell
data S = Sym String | Nil | Tr | Fl | Cons S S deriving (Eq, Show)
data T = Var String |
Combine T T T |
Lam String T |
Eps String T |
Eval T T |
Wrap T |
Env [(String, T)] |
Sexp S deriving (Eq, Show)
@cfhammill
cfhammill / logged-eval-tidy.r
Created October 27, 2018 01:44
Log what symbols are hit in your data with tidy_eval
library(rlang)
logged_eval_tidy <-
function(expr, data, env = caller_env()){
dm <- as_data_mask(data)
ae <- as_data_mask(list())
nms <- character(0)
te <- environment()
@cfhammill
cfhammill / introToGraphs.rmd
Created April 14, 2015 12:51
Introduction to Igraph and Shiny Presentation
---
title: "An Introduction to Graphs"
author: "Chris Hammill"
date: '2015-04-01'
output:
beamer_presentation:
theme: "Boadilla"
fig_crop: false
keep_tex: true
template: chris.beamer
@cfhammill
cfhammill / instructions.md
Created April 13, 2015 23:07
A work-around for fixing code sizing in beamer presentations created with R Markdown

Instructions

To use this gist, download the resizeTemplate.beamer file to the same folder and your R markdown presentation.

Then add

template: resizeTemplate.beamer

To your yaml data block after beamer_presentation

@cfhammill
cfhammill / IpythonKnitEngine.md
Last active August 29, 2015 14:15
This gist is an engine for Knitr to allow python code to be executed with ipython in when using Knitr and R Markdown

I'm currently translating a python statistical package to R and wanted to benchmark the packages side-by-side in an R Markdown document. So I poked around in knitr's internals to figure out how alternative code engines worked. It's pretty straight forward, just find the program you want to use, and pass it the code in your chunk. I wrote a little code snippet to do exactly that in my document (I found using stock python didn't execute my code as expected, so wanted to switch to ipython). Hopefully it may be of use to you.

In order to use the engine in an R Markdown document, download and source ipythonKnitEngine.R then include your python chunks in your document(example below).

```{r, engine = "ipython", engine.path = "path/to/ipython/"}
#Python code to execute
```

The engine.path needs to lead to the folder containing the ipython executable (not the file itself). Currently the engine path must be specified, even if ipython is in your search path, I will try to fix this in the near futu