This file contains hidden or 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
Try importing these files with readr |
This file contains hidden or 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
to.minutes <-function(x) { | |
#regexpr("(\\d{1,2}:)?\\d{1,2}\\.\\d{1,2}", x, perl=T) | |
idx<-gregexpr(":", x, perl=T) | |
# try to turn hh:mm:ss interval to a count in minutes. | |
mapply(function(ss,ids) { | |
if(length(ids)==2) { | |
as.numeric(substr(ss,1,ids[1]-1)) * 60 + | |
as.numeric(substr(ss,ids[1]+1, ids[2]-2))+ as.numeric(substr(ss,ids[2]+1, nchar(ss)))/60 | |
} else if (length(ids)==1) { | |
as.numeric(substr(ss,1,ids[1]-1)) + as.numeric(substr(ss,ids[1]+1, nchar(ss)))/60 |
This file contains hidden or 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
export <- function(...) { | |
dots <- substitute(...()) | |
dp <- sapply(dots, deparse) | |
names <- if (is.null(names(dots))) rep("", length(dots)) else names(dots) | |
names[names==""] <- dp[names==""] | |
for(i in seq_along(dots)) { | |
assign(names[i], eval(dots[[i]], parent.frame()), envir=parent.frame(2)) | |
} | |
} |
This file contains hidden or 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
# from the sample data included with http://www.ucancode.net/Visual_C_Control/Draw-table-shape-vc-example-periodic.htm | |
"AtomicNumber","AtomicWeight","GroupNumber","GroupName","Period","Block","CASRegistryID","ElementName","ElementSymbol","DiscoveryDate","DiscovererName","Row","Column" | |
1,1.00,5,"Non-metals","1","s-block","1333-74-0","Hydrogen","H","1766","Henry Cavendish",1,1 | |
2,0.00,4,"Noble gases",,,,"Helium","He",,,1,18 | |
3,0.00,0,"Alkali earth",,,,"Lithium","Li",,,2,1 | |
4,0.00,1,"Alkaline earth",,,,"Beryllium","Be",,,2,2 | |
5,0.00,3,"Metalloids",,,,"Boron","B",,,2,13 | |
6,0.00,5,"Non-metals",,,,"Carbon","C",,,2,14 | |
7,0.00,5,"Non-metals",,,,"Nitrogen","N",,,2,15 | |
8,0.00,5,"Non-metals",,,,"Oxygen","O",,,2,16 |
This file contains hidden or 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
capture <- function(...) { | |
vars<-sapply(substitute(...()), deparse) | |
pf <- parent.frame() | |
Map(assign, vars, mget(Filter(exists, vars), envir=pf, inherits = TRUE), MoreArgs=list(envir=pf)) | |
} |
This file contains hidden or 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
{ | |
"glossary": { | |
"title": "example glossary", | |
"GlossDiv": { | |
"title": "S", | |
"GlossList": { | |
"GlossEntry": { | |
"ID": "SGML", | |
"SortAs": "SGML", | |
"GlossTerm": "Standard Generalized Markup Language", |
This file contains hidden or 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
makeglm <- function(formula, ..., family, data=NULL) { | |
dots <- list(...) | |
out<-list() | |
tt <- terms(formula, data=data) | |
if(!is.null(data)) { | |
mf <- model.frame(tt, data) | |
vn <- sapply(attr(tt, "variables")[-1], deparse) | |
if((yvar <- attr(tt, "response"))>0) | |
vn <- vn[-yvar] |
This file contains hidden or 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
# withX() will create an environment for the first parameter and all of your named parameters | |
# if the first parameter is not named, it will be called "X" in the enviroment | |
# there may be exactly one unnamed expression | |
# this unnamed parameter will be eval'ed in the envir defined by your named parameters | |
# If no object is returned from the expression, the newest value of the first parameter is returned invisibly | |
# this can avoid repeating awkward expressions | |
#this is a lot like `with()` but instead of working within the variable, | |
# the value itself is added to the enviroment as a variable |
This file contains hidden or 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
classMethods <- function(cl) { | |
if(!is.character(cl)) { | |
cl<-class(cl) | |
} | |
ml<-lapply(cl, function(x) { | |
sname <- gsub("([.[])", "\\\\\\1", paste0(".", x, "$")) | |
m <- methods(class=x) | |
if(length(m)) { | |
data.frame( | |
m=as.vector(m), |