Skip to content

Instantly share code, notes, and snippets.

View MansMeg's full-sized avatar

Måns Magnusson MansMeg

View GitHub Profile
@MansMeg
MansMeg / nsc_project_move.sh
Last active March 6, 2016 13:02
Script to move move from old to new projects at NSC
#!/bin/bash
# Assumptions:
# None
#
# Description:
# Moves a full folder from an old project account to a new project account at NSC (Gamma)
#
LIUNAME=x_manma
OLD_NSC_ACCOUNT=liu-2015-00017-47
NEW_NSC_ACCOUNT=liu-2015-00020-3
@MansMeg
MansMeg / msg_progress_bar.R
Last active March 3, 2016 20:23
R object to create a message progress bar in R. Similar to txtProgressBar but output the progress bar using message() instead of cat(), preferred in R packages.
#' Message progress bar
#'
#' @description
#' A simple progress bar to use in R packages where messages are prefered to console output.
#'
#' @field iter Total number of iterations
#' @field i Current iteration
#' @field width Width of the R console
#' @field width_bar Width of the progress bar
#' @field progress The number of character printed (continous)
@MansMeg
MansMeg / gist:bbfadc771cb15b56b4cd
Last active September 10, 2015 12:00
Download private files from github
#' Download a (private) file from github using a personal access token
#'
#' @description
#' Download a file from a private repository using GitHub API v3.
#'
#' @param repo Repository as :owner/:repo
#' @param path Path to file
#' @param pat Personal access token
#'
#' @details
@MansMeg
MansMeg / gist:1c68c0a36850601fe93c
Created September 7, 2015 16:34
How to find the encoding of a file in R
stringi::stri_enc_detect(content(r, "raw"))
@MansMeg
MansMeg / mutiplot.R
Last active August 29, 2015 14:06
Function to put multiple ggplots together to one plot.
#' @title
#' Multiple plot function
#'
#' @description
#' ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects).
#' If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
#' then plot 1 will go in the upper left, 2 will go in the upper right, and
#' 3 will go all the way across the bottom.
#'
#' @param cols Number of columns in layout
@MansMeg
MansMeg / InverseGammaAndChiSquare.R
Last active September 25, 2018 13:53
Random draw from inverse gamma and inverse chisquare
#' @title
#' rInvGamma
#'
#' @description
#' Random draws from the inverse gamma distribution.
#'
#' @param n See n in rgamma()
#' @param shape Alpha
#' @param scale Beta
#'
#####################
# R function for downloading plain-text data from GitHub
# Christopher Gandrud
# 7 January 2013
#####################
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package
source_GitHubData <-function(url, sep = ",", header = TRUE)
{
#####################
# R function for downloading plain-text data from GitHub
# Christopher Gandrud
# 7 January 2013
#####################
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package
source_GitHubData <-function(url, sep = ",", dec=".", header = TRUE)
{