Skip to content

Instantly share code, notes, and snippets.

library(RcppAlgos)
#' Calculate number of choices made by Shannon's bot
#' @description
#' Shannon's bot selects randomly answers to a multiple choice question the same
#' number of times as there is options to choose from.
#' It moves to the next question if at least 1 choice remains chosen after all
#' choices are made.
#' If not, i.e. nothing remains selected, the question is retried again, until
#' at least one choice remains.
@nstjhp
nstjhp / basic_test_stan_cores_script.R
Created December 22, 2021 17:27
Test if R/Rstudio can run Stan with multiple cores or just hangs
# Test if R/Rstudio can run Stan with multiple cores or just hangs
t1dat = list(N=100, y = rnorm(100))
default_Stan_normal = "
// The input data is a vector 'y' of length 'N'.
data {
int<lower=0> N;
vector[N] y;
}
@nstjhp
nstjhp / git_review_PR.txt
Last active May 18, 2021 12:08
Review a pull request before merging
git fetch origin pull/NN/head:prNN ## check the PR number - this is what goes between pull and head. After the : is the name of the branch - makes sense to call it like this prID where ID is PR number
git checkout prNN ## After checking out you can compile, edit, do whatever to the PR branch
git checkout main ## If you're happy switch back to main branch before merging
git merge --no-ff prNN
git status
git log
git push origin main ## push to Github
@nstjhp
nstjhp / rstan_test_script.R
Created March 2, 2021 18:43 — forked from rasmusab/rstan_test_script.R
A short script you can use to test if rstan is installed and working correctly.
# Prior to the tutorial make sure that the script below runs without error on your R installation.
# What you need is a working installation of Stan: http://mc-stan.org/ .
# For installation instructions, see here:
# https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
# After installation you should be able to run this script which should output
# some summary statistics and some pretty plots, :)
# Generating some fake data
set.seed(123)
@nstjhp
nstjhp / list_obj_sizes.R
Created January 8, 2021 13:50
Get all R object sizes
# From comments on https://stackoverflow.com/a/19610840/3275826
# and https://stackoverflow.com/a/1395280/3275826
#
# Using mget can avoid the problems of having an object with the same name
# as the function argument confusing the results, here `x` in the line
# `sizes = sapply(list_obj, function(x) object.size(get(x)), simplify = FALSE)`
# If you were to use this instead and assigned x to a large enough object,
# then the output of this function would be different to a straight object.size(x) call
#
# object.size can be replaced by pryr::object_size
@nstjhp
nstjhp / transpose.awk
Created March 19, 2014 13:16
Transpose a tab separated file using AKW from a SO answer
#!/usr/bin/awk -f
# http://stackoverflow.com/a/1729980/3275826
# Make sure this directory/file is in your $PATH
# then call as transpose.awk fileName
{
for (i=1; i<=NF; i++) {
a[NR,i] = $i
}
}
NF>p { p = NF }
/* Adapted from a .css file that is Copyright (c) 2009-2013 Jeremy Ashkenas
* https://github.com/jashkenas/docco
* NP modified 02/03/14
* MIT licence */
/*--------------------- Typography ----------------------------*/
@font-face {
font-family: 'fleurons';
src: url('http://jashkenas.github.io/docco/resources/linear/public/fonts/fleurons.eot');
src: url('http://jashkenas.github.io/docco/resources/linear/public/fonts/fleurons.eot?#iefix') format('embedded-opentype'),
{
"metadata": {
"name": "plos_one_analysis"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{