Skip to content

Instantly share code, notes, and snippets.

@sjewo
sjewo / linebreaks.R
Created November 28, 2012 14:09
Zeilenumbrüche für Label
# Funktion um Zeilenumbrüche nach m Zeichen einfügen
# Argumente:
# txt = Vektor mit Zeichenketten
# m = Anzahl an Zeichen nach denen ein Zeilenumbruch eingefügt werden soll (default: 10)
# bchar = Trennzeichen (default: \n)
breaking <- function(txt, m, bchar) {
out <- ""
for (i in 1:length(txt)) {
if (nchar(gsub(paste('^.*',
@sjewo
sjewo / ping.r
Created December 11, 2012 14:53
ping function for R (linux)
ping <- function(x,stderr=FALSE,stdout=FALSE,...){
ping <- system(paste("ping -c1", x, "> /dev/null"),
intern=F,
ignore.stdout=stdout,
ignore.stderr=stderr)
return(if (ping == 0) TRUE else FALSE)
}
@sjewo
sjewo / combinec.R
Created February 13, 2013 18:50
R-Funktion um zwei Vektoren zeilenweise zusammenzufassen (http://stackoverflow.com/a/12512327)
# Funktion um zwei Vektoren zeilenweise zusammenzufassen
# Argumente:
# A,B = Vektor
# Quelle: http://stackoverflow.com/a/12512327
process <- function(A,B) {
x <- cbind(A,B)
apply(x,1,function(x) {
if(sum(is.na(x))==1) {na.omit(x)} else # ein fehlender Wert
if(all(is.na(x))) {NA} else # beide fehlend
plot.nnet<-function(mod.in,nid=T,all.out=T,all.in=T,wts.only=F,rel.rsc=5,circle.cex=5,node.labs=T,
line.stag=NULL,cex.val=1,alpha.val=1,circle.col='lightgrey',pos.col='black',neg.col='grey',...){
require(scales)
#gets weights for neural network, output is list
#if rescaled argument is true, weights are returned but rescaled based on abs value
nnet.vals<-function(mod.in,nid,rel.rsc){
library(scales)
@sjewo
sjewo / plot.nn.r
Last active December 14, 2015 14:18
Modified plot function for neuralnet objects; similar to http://beckmw.wordpress.com/2013/03/04/visualizing-neural-networks-from-the-nnet-package/ for the nnet package.
# based on plot.nn, from the neuralnet R package by Stefan Fritsch, Frauke Guenther
# plotting function for neuralnet objects
#
# additional arguments:
# varwidth=FALSE FALSE: equal lwd for vertices, TRUE: lwd proportional to weights
# lwd.max=5 max lwd for vertices
# col.pos='black' default color for positive weights
# col.neg='grey' default color for negative weights
# col.text='black' default color for vertex label
# all.in=TRUE TRUE: display all input variables, replace with variable names to display only selected variables
@sjewo
sjewo / rex_action_keep-latex.php
Created May 27, 2013 15:26
Action for redaxo CMS which escapes \r,\f,\n only for latex code in square brackets \[ \].
<?php
// escape \r,\f,\n in latex code in square brackets \[ \]
$REX_ACTION['VALUE']['1']=preg_replace_callback(
'#\\[(.+?)\\]#s',
function ($matches) {
$search = array('\\n','\\r','\\f');
$replace = array('\\\\n','\\\\r','\\\\f');
return str_replace($search, $replace, $matches[0]);
},
$REX_ACTION['VALUE']['1']);
@sjewo
sjewo / wms_proto.R
Created October 28, 2013 11:12 — forked from jlehtoma/wms_proto.R
# Author: Joona Lehtomäki <joona.lehtomaki@gmail.com>
# Updated: 13.11.2011
# Version: 0.0.1
if (!require("rgdal")) {
install.packages("rgdal")
}
if (!require("raster")) {
install.packages("raster")
/*
* NAME
*
* statistics-distributions.js - JavaScript library for calculating
* critical values and upper probabilities of common statistical
* distributions
*
* SYNOPSIS
*
*
@sjewo
sjewo / xlsxToR.r
Created February 19, 2014 18:27 — forked from schaunwheeler/xlsxToR.r
library(XML)
library(plyr)
library(pbapply)
xlsxToR <- function(file, keep_sheets = NULL, header = FALSE) {
temp_dir <- file.path(tempdir(), "xlsxToRtemp")
suppressWarnings(dir.create(temp_dir))
file.copy(file, temp_dir)
@sjewo
sjewo / package.R
Created February 21, 2014 09:33 — forked from jbryer/package.R
#' Simplified loading and installing of packages
#'
#' This is a wrapper to \code{\link{require}} and \code{\link{install.packages}}.
#' Specifically, this will first try to load the package(s) and if not found
#' it will install then load the packages. Additionally, if the
#' \code{update=TRUE} parameter is specified it will check the currently
#' installed package version with what is available on CRAN (or mirror) and
#' install the newer version.
#'
#' @param pkgs a character vector with the names of the packages to load.