Created
September 10, 2014 09:16
-
-
Save stephlocke/67781f2263f7fa2639a6 to your computer and use it in GitHub Desktop.
Provides indicative view of what I'm trying to achieve by changing functions and testing the before and after results
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
# Example functions that would be in seperate files in the R directory of the package | |
simpleFn1 <- function(a){ | |
myConst <- 10 | |
a*myConst | |
} | |
simpleFn2 <- function(a){ | |
myConst <- 5 | |
a/myConst | |
} | |
myComplexFn <- function(a=iris){ | |
library("data.table") | |
myDT<-as.data.table(a) | |
myDT[,lapply(.SD,simpleFn1),by=Species] | |
} | |
# Current version of function results | |
State1<-myComplexFn()[,lapply(.SD,mean),by=Species] | |
# Change to function | |
myComplexFn<-function(a=iris){ | |
library("data.table") | |
myDT<-as.data.table(iris) | |
myDT[,lapply(.SD,simpleFn1),by=Species] | |
myDT[,lapply(.SD,simpleFn2),by=Species] | |
} | |
# Current version of function results | |
State2<-myComplexFn()[,lapply(.SD,mean),by=Species] | |
# Results | |
State1 | |
State2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment