Skip to content

Instantly share code, notes, and snippets.

View petermeissner's full-sized avatar
💻
githubbing

Peter Meissner petermeissner

💻
githubbing
View GitHub Profile
@petermeissner
petermeissner / package.r
Last active August 29, 2015 14:21
function that loads packages and installs them if need be
# function that loads packages
package <- function(pkg, repo){
pkg <- as.character(as.list(match.call())$pkg)
repo <- as.character(as.list(match.call())$repo)
if ( !(pkg %in% as.data.frame(installed.packages())$Package) ){
if( length(repo)!=0 ){
package("devtools")
devtools::install_github(paste0(repo,"/",pkg))
}else{
install.packages(pkg)
@petermeissner
petermeissner / modus.r
Created April 23, 2015 15:51
function for calculating the modus
#' function for getting mode source: http://stackoverflow.com/a/8189441/1144966
#' @param x vector for which the mode should be returned
modus <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
@petermeissner
petermeissner / browse_df_as_html.r
Last active August 29, 2015 14:18
An R function allowing to browse R data frames as HTML files
### Description ###
# author: peter meissner (https://github.com/petermeissner | http://pmeissner.com)
# purpose: Browsing data frames in R is annoying.
# The function provided here allows to browse data frames within the
# browser using HTML and some JavaScript.
#' function for making html table
#' @param x data.frame or matrix to be transformed
@petermeissner
petermeissner / to_char_bars.md
Last active August 29, 2015 14:16
How to get numbers transformed to character bar charts ... to_char_bars()
require(httr)
## Loading required package: httr
#!/path/2/Rscript
# License: CC0 (just be nice and point others to where you got this) Author:
# Robert M Flight <[email protected]>, github.com/rmflight
#
# This is a post-commit hook that after a successful commit subsequently
# increments the package version in DESCRIPTION and commits that. Analogous to
# the pre-commit at https://gist.github.com/rmflight/8863882, but useful if you
# only have good reasons for not doing it on the pre-commit.
#
@petermeissner
petermeissner / gist:6dc6cf6de97b0c9a6dc7
Last active August 29, 2015 14:13
Rmd snippet that translates itself into Rpres
[...]
```{r, include=FALSE}
RMDtoRpres <- function(fname){
require(stringr)
text <- readLines(fname, encoding="UTF-8")
text <- paste(text, collapse="\n")
author <- str_replace_all(str_extract(text,'author: ".*?\n'),'["\n]',"")
date <- str_replace_all(str_extract(text,"date: '.*?\n"),'["\n]',"")
title <- str_replace(str_replace_all(str_extract(text,'title: ".*?\n'),'["\n]',""),"title: ","")