Skip to content

Instantly share code, notes, and snippets.

View floswald's full-sized avatar
👋

Florian Oswald floswald

👋
View GitHub Profile
@floswald
floswald / vector.r
Created July 8, 2014 10:13
Rcpp::NumericVector -> std::vector
library(inline)
body='NumericVector xx(x);
std::vector<double> X(xx.begin(),xx.end());
for (int i = 0;i<X.size();i++) {
std::cout << "X[i] = " << X.at(i) << std::endl;
}
return (xx);'
tfun = cxxfunction(signature(x="numeric"),body,plugin="Rcpp")
#!/bin/bash
echo "starting qsub script file"
source ~/.bash_profile
date
module load sge/2011.11
# here's the SGE directives
# ------------------------------------------
#include "MyClass.h"
// Define Class members
// =====================
double MyClass::GetSolution( ) {
// point the pt_MyClass element to this class
p->pt_MyClass = this;
#include <gsl/gsl_roots.h>
#include <gsl/gsl_interp.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_errno.h>
#include <iostream>
// forward definition of param struct
struct gsl_f_pars;
#!/usr/bin/env ruby -w
head, treshold = ARGV
head ||= 'HEAD'
Megabyte = 1000 ** 2
treshold = (treshold || 0.1).to_f * Megabyte
big_files = {}
IO.popen("git rev-list #{head}", 'r') do |rev_list|
rev_list.each_line do |commit|
@floswald
floswald / benchmark.r
Created May 17, 2013 16:09
benchmarking armamax against apply and pmax
library(inline)
library(Rcpp)
cpp <- 'arma::mat A = Rcpp::as<arma::mat>(X_);
arma::vec y(A.n_rows);
arma::rowvec tmp(A.n_cols);
for (int i=0; i<A.n_rows; i++) {
tmp = A.row(i);
y(i) = tmp.max();
}
@floswald
floswald / country.r
Created January 29, 2013 14:20
country plot code
library(xlsx)
cdat <- read.xlsx(file="~/datasets/ReinhardRogoff/18_data.xls",sheetName="Aut.Ita.UK.US")
cdat <- cdat[,-c(5,6,7)]
library(reshape)
library(ggplot2)
m <- melt(cdat,c("Year","Country"))
p <- ggplot(m,aes(x=Year,y=value)) + geom_line(aes(color=variable),size=1) + facet_wrap(~Country,ncol=1) + scale_y_continuous(name="Public (Public and Private) debt to GDP (GNP) ratios") + theme(legend.position="top")
@floswald
floswald / knitr.lyx
Created November 4, 2012 16:45
problem with lyx and knitr
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\use_default_options true
\begin_modules
knitr
\end_modules
\maintain_unincluded_children false
@floswald
floswald / rgl.r
Created October 3, 2012 11:38
demo for quasi-concave functions
# R script accompanying quasi-concave, concave etc note
if(!require(rgl)) install.packages('rgl')
require(rgl)
# setup data
nx <- 50 # points into x direction
ny <- 50 # points into y
@floswald
floswald / googleVis_at_RSS_2012.Rmd
Created September 11, 2012 08:02 — forked from mages/googleVis_at_RSS_2012.Rmd
googleVis at RSS 2012
Creating interactive web graphs with R: Overview and googleVis tutorial
========================================
```{r results='asis', echo=FALSE, message=FALSE, tidy=FALSE}
library(googleVis)
df <- data.frame(Postcode=c("TF3 4JH", "EC1Y 8LX"),
Tip=c("Telford", "RSS"))
## Tree map
T <- gvisTreeMap(Regions, "Region", "Parent", "Val", "Fac",
options=list(width=250, height=150,