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
DT <- as.data.table(iris) | |
DT[, MONTHS := sample(month.abb, size = .N, replace = TRUE)] | |
DT[, LETTERS := sample(LETTERS[rep(1:5, 3)], size = .N, replace = TRUE)] | |
DT | |
grp1 <- c("Species", "LETTERS") | |
grp2 <- c("MONTHS") | |
resDT <- DT[, .(grpDT = { | |
res <- list(as.data.table(.SD)[, .N, grp2]) | |
res |
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
# DEFINE HELPER FUNS AND SET INIT OPTIONS --------------------------------- | |
options(devtools.name = "Bobby Fatemi") | |
options(devtools.desc.license = "file LICENSE") | |
options(devtools.desc.author = 'person(email = "[email protected]", role = c("aut", "cre"), given = "Bobby", family = "Fatemi")') | |
options(devtools.desc = list( | |
Description = "[DOCUMENTATION NEEDED] DESCRIPTION.", | |
Title = "[DOCUMENTATION NEEDED] TITLE") | |
) |
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
packageStartupMessage(" | |
##********* Surgical Science **********## | |
# -------------------------------- # | |
# Medical Outcomes Analysis # | |
# -------------------------------- # | |
# Comparison of daVinci Robotic # | |
# Surgery Patients and Patients # | |
# of other surgical modalities # | |
# -------------------------------- # | |
# # |
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
# One line to keep rows such that there are no NAs across all columns | |
dt[Reduce("&", lapply(dt, function(i) !is.na(i)))] |
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
j <- function(x) { | |
y <- 2 # Define y | |
# j returns this function | |
function() { | |
c(x, y) | |
} | |
} |
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
today <- Sys.Date() | |
yearEnd <- as.Date(paste0(year(today), "-12-31")) | |
daysVec <- seq(today, yearEnd, by=1) |
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
### Example of accessing the function call stack | |
IsHungry <- function(){ | |
e <- substitute(cat(sub("\\(.*\\)", " ", deparse(sys.calls()[[i]])))) | |
Bob <- function(n){ | |
Loves <- function(n){ | |
Burgers <- function(n){ | |
TheEnd <- function(n){ | |
invisible(sapply(1:n, function(i) eval(e, list(i)))) | |
} | |
TheEnd(sys.nframe()) |
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
require(stats) | |
## Extends the example for 'switch' | |
center <- function(x, type = c("mean", "median", "trimmed")) { | |
type <- match.arg(type) | |
switch(type, | |
mean = mean(x), | |
median = median(x), | |
trimmed = mean(x, trim = .1)) | |
} |
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
#!/bin/bash | |
LIST=$1 | |
PACKAGE_LIST=$(dpkg --get-selections | awk '{ print $1 }' | grep -v -e "-dbg" | cut -f1 -d":") | |
getsize () { | |
size=$(apt-cache --no-all-versions show $1 | grep Installed-Size | awk '{ print $2 }') | |
((NEEDED+=$size)) | |
} |
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
apt-get update |pv -tN "Updating" > /dev/null & pid=$! | |
trap "kill $pid 2> /dev/null" EXIT | |
while kill -0 $pid 2> /dev/null; do | |
tput cup 10 10 | |
done | |
trap - EXIT |