This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(compiler) | |
inFun <- Vectorize(function(x,y,z){ | |
return((x^2)+y*z) | |
},SIMPLIFY = FALSE) | |
inFun1 <- cmpfun(Vectorize(function(x,y,z){ | |
return((x^2)+y*z) | |
},SIMPLIFY = FALSE),options = list(optimize=1)) | |
inFun2 <- cmpfun(Vectorize(function(x,y,z){ | |
return((x^2)+y*z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Things to do (MacOS Sierra): | |
1. make a file: src/Makevars that contains: | |
PKG_CFLAGS = `gsl-config --cflags` | |
PKG_LIBS = `gsl-config --libs` | |
PKG_CPPFLAGS = -I../inst/include | |
2. the DESCRIPTION should include: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################# | |
# | |
# MASH | |
# R6-ified | |
# How to nest interacting classes | |
# Hector Sanchez & Sean Wu | |
# May 9, 2017 | |
# | |
################################################################# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################# | |
# Optimization with constraints via parameter transform | |
# Sean Wu | |
############################################################# | |
# same as qlogis | |
logit <- function(x){ | |
log(x/(1-x)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
// quickly find the position of the minimum and maximum elements of an STL vector | |
int main() | |
{ | |
std::vector<int> v = { 3, 9, 1, 4, 2, 5, 9 }; | |
auto result = std::minmax_element(v.begin(), v.end()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# passArgsReplicate: how to pass additional named args as ... to function in replicate | |
passArgsReplicate <- function(n, func, ...){ | |
args = as.list(substitute(list(...)))[-1L] | |
replicate(n = n,expr = do.call(func,args),simplify = FALSE) | |
} | |
# test calling and using global variables on different parallel processes | |
library(parallel) | |
parTest <- function(arg){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. mypython=$(which python) | |
2. myvar=$(hostname)@$(whoami) | |
3. mkdir -p temp/proj{1..3}/{code,data} | |
4. wc -l FILE | |
5. | |
#first 3 lines in file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# Lecture | |
################################################################################ | |
# BASH stuff: | |
ls -tr *.R # gives you the list of the R files modified most recently (closest in time at bottom, farthest in time at top) | |
ls -tr *.R | tail - n 5 # last five things modified | |
ls -tr *.R | tail - n 5 | grep optim # look for files called 'optim' in the name | |
grep 'example.pdf' $(ls -tr *.R) # look for example.pdf in the stuff from inside $(.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download the data | |
wget -O apricots.zip "http://data.un.org/Handlers/DownloadHandler.ashx?DataFilter=itemCode:526&DataMartId=FAO&Format=csv&c=2,3,4,5,6,7&s=countryName:asc,elementCode:asc,year:desc" | |
unzip -p apricots.zip > apricots.csv | |
# split into region and country | |
grep -v "+" apricots.csv > countries.csv | |
grep "+" apricots.csv > regions.csv | |
# put all the 2005 data to a new countries05.csv file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
using namespace Rcpp; | |
// C code with Rcpp; basic example | |
// [[Rcpp::export]] | |
extern "C" SEXP rngScopeCppScalar() { | |
NumericVector x(4); |
OlderNewer