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
stopper <- function(fun) | |
{ | |
stop(paste("in match_src() : function fun='", fun, "' not found", sep=""), call.=FALSE) | |
} | |
match_src <- function(fun, pattern, ignore.case=FALSE, perl=FALSE, value=FALSE, fixed=FALSE, useBytes=FALSE, invert=FALSE, remove.comments=TRUE) | |
{ | |
### This is really too complicated, I apologize | |
err <- try(test <- is.character(fun), silent=TRUE) | |
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
# The task: | |
# Print strings from "a" to "zzzzz" without using any loop or conditional statements. Don't just write all 1000 permutations out by hand. The output should look like this: | |
# a | |
# b | |
# c | |
# ... | |
# aa | |
# ab | |
# ac |
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(Rcpp) | |
body <- " | |
SEXP foo(const int len, Rcpp::NumericVector pr) | |
{ | |
Rcpp::IntegerVector ret(len); | |
RNGScope(); | |
for (int i=0; i<len; i++) | |
{ |
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
"+" <- function(e1, e2){ | |
if (typeof(e1) == "character" && typeof(e2) == "character") | |
return(paste0(e1, e2)) | |
else | |
return(base::`+`(e1, e2)) | |
} | |
"a" + "b" | |
1 + 2 | |
"1" + 2 |
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
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# Version 2, December 2004 | |
# | |
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> | |
# | |
# Everyone is permitted to copy and distribute verbatim or modified | |
# copies of this license document, and changing it is allowed as long | |
# as the name is changed. | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
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
set.seed(1234) | |
x <- rnorm(10)/1e7 | |
quantile(x, type=1) | |
# 0% 25% 50% 75% 100% | |
# -2.345698e-07 -8.900378e-08 -5.644520e-08 4.291247e-08 1.084441e-07 | |
quantile(x, type=4) | |
# 0% 25% 50% 75% 100% | |
# -2.345698e-07 -1.048552e-07 -5.644520e-08 3.532770e-08 1.084441e-07 |
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
install_if_needed <- function(pkgs, lib=NULL, repos=getOption("repos"), | |
contriburl=contrib.url(repos, type), method, available=NULL, destdir=NULL, | |
dependencies=NA, type=getOption("pkgType"), configure.args=getOption("configure.args"), | |
configure.vars=getOption("configure.vars"), clean=FALSE, Ncpus=getOption("Ncpus", 1L), | |
verbose = getOption("verbose"), libs_only=FALSE, INSTALL_opts, quiet=FALSE, | |
keep_outputs=FALSE, | |
check_version=TRUE, | |
...) | |
{ | |
installed <- installed.packages() |
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
setMethod("print", signature(x="logical"), | |
function(x) | |
{ | |
if (is.na(x)) | |
base::print("who knows?") | |
else if (x) | |
base::print("to be sure") | |
else | |
base::print("nope") | |
} |
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
### Determining (poorly) the sex of a person based on their name. | |
### Based on this post: http://thedailywtf.com/articles/genderize | |
genderize <- function(name) | |
{ | |
regex <- "(ua|pher|andy|elijah)$" | |
if (grepl(x=name, pattern=regex, ignore.case=TRUE)) | |
return("male") | |
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(babynames) | |
genderize <- function(name) | |
{ | |
regex <- "(ua|pher|andy|elijah)$" | |
if (grepl(x=name, pattern=regex, ignore.case=TRUE)) | |
return("male") | |
regex <- "(a|i|y|ah|ee|et|ette|elle|fer|ine|lyn|ie|anne|een|en|er|yn|ynn|kim|rachel|lind|pam|sue)$" |
OlderNewer