Skip to content

Instantly share code, notes, and snippets.

View bfatemi's full-sized avatar
🎯
In my zone

Bobby Fatemi bfatemi

🎯
In my zone
View GitHub Profile
packageStartupMessage("
##********* Surgical Science **********##
# -------------------------------- #
# Medical Outcomes Analysis #
# -------------------------------- #
# Comparison of daVinci Robotic #
# Surgery Patients and Patients #
# of other surgical modalities #
# -------------------------------- #
# #
@bfatemi
bfatemi / init_script.R
Last active August 12, 2017 04:57
Launch New Package
# 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")
)
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
@bfatemi
bfatemi / example_loading_page.R
Created April 4, 2019 01:54
Loading page for shiny/R app implemented with the shinyjs R package.
library(shiny)
library(shinyjs)
load_data <- function() {
Sys.sleep(2)
hide("loading_page")
show("main_content")
}
ui <- fluidPage(
@bfatemi
bfatemi / example_quantile_reg.R
Created April 4, 2019 01:55
Example of plotting quantile regression in R.
install.packages("quantreg")
pdt <- dt[durProc < 400 &
ExpIndex < 500 &
ExpIndex > 4]
pdt2 <- pdt[, .(aveDur = mean(durProc)), ExpIndex][order(ExpIndex)]
m <- ggplot(pdt2, aes(ExpIndex, aveDur)) +
@bfatemi
bfatemi / abcExample.r
Created June 5, 2019 03:12
activeBinding
ABC <- local({
x <- 1
function(v) {
if (missing(v)){
cat("get\n")
} else {
cat("set\n")
x <<- v
}
x
@bfatemi
bfatemi / implementDF.R
Created June 5, 2019 21:57
Better way to define a data.table (implement using structure)
# Usecases:
# when creating many R environments and each have independent data-set
ll <- list(
as.factor(c(2001, 2002, 2004, 2006)),
I(c(2001, 2002, 2004, 2006)),
ordered(c(2001, 2002, 2004, 2006)),
as.double(c(366.3240, 365.4124, 366.5323423, 364.9573234)),
# Change directory to the current Finder directory
cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
#!/bin/bash
set -e
set -u
#
# GROUP: min user access...
# - can connect to database
# - can access schema
# - can read schema tables
#
##
## POSTGRES LITE DOCKERFILE- create db, user/pwd, and open listening
##
FROM postgres:11.1-alpine
ADD ./init.sh /docker-entrypoint-initdb.d/.
ENV PGDATA /var/lib/postgresql/data
EXPOSE 5432