require(MASS)
## Loading required package: MASS
#'% Using Dates and Times in R | |
#'% Bonnie Dixon | |
#'% 14-02-10 15:09:57 | |
#' | |
#' *Today at the [Davis R Users' | |
#' Group](http://www.noamross.net/davis-r-users-group.html), [Bonnie | |
#' Dixon](http://ffhi.ucdavis.edu/people/directory/bmdixon) gave a tutorial on the | |
#' various ways to handle dates and times in R. Bonnie provided this great script | |
#' which walks through essential classes, functions, and packages. Here it is piped through | |
#' `knitr::spin`. The original R script can be found as a gist |
# http://aschinchon.wordpress.com/2014/10/13/beautiful-curves-the-harmonograph/ | |
f1 <- jitter(sample(c(2, 3), 1)) | |
f2 <- jitter(sample(c(2, 3), 1)) | |
f3 <- jitter(sample(c(2, 3), 1)) | |
f4 <- jitter(sample(c(2, 3), 1)) | |
d1 <- runif(1, 0, 1e-02) | |
d2 <- runif(1, 0, 1e-02) | |
d3 <- runif(1, 0, 1e-02) | |
d4 <- runif(1, 0, 1e-02) |
# Read ICD-9 diagnosis and procedure code descriptions | |
descLength <- "LONG" # Change "SHORT" to "LONG" for more detailed description | |
# Use Version 32 from cms.gov | |
# Version 32 Full and Abbreviated Code Titles – Effective October 1, 2014 | |
# Update if necessary | |
url <- "http://www.cms.gov/Medicare/Coding/ICD9ProviderDiagnosticCodes/Downloads/ICD-9-CM-v32-master-descriptions.zip" | |
url <- "http://www.ohsu.edu/xd/outreach/oregon-rural-health/data/rural-definitions/upload/OR-Zip-Codes-Urban-Rural-Designations.xlsx" | |
f <- tempfile() | |
download.file(url, f, mode="wb") | |
if (!require(xlsx)) { | |
repos <- "http://cran.us.r-project.org" | |
install.packages("xlsx", dependencies=TRUE, repos=repos) | |
rm(repos) | |
} | |
require(xlsx) | |
ruca <- read.xlsx(f, 1) |
callSAS <- function (f, path=tempdir(), workDir=sprintf("E:\\Share\\Temp\\%s\\SASWork", Sys.info()["user"])) { | |
# Usage: | |
# > callSAS("getClaimsMed.sas") | |
if (grepl(".sas$", f)) { | |
exeFile <- "C:\\Program Files\\SASHome\\SASFoundation\\9.3\\sas.exe" | |
sasFile <- sprintf("%s\\%s", path, f) | |
logFile <- sprintf("%s\\%s", path, gsub(".sas$", ".log", f)) | |
cmd <- sprintf("\"%s\" -sysin \"%s\" -log \"%s\" -print \"%s\" -work \"%s\"", | |
exeFile, | |
sasFile, |
callStata <- function (f, path=tempdir(), tempPath="E:\\Share\\Temp") { | |
# Usage: | |
# > callStata(do-file-name-as-character-object, | |
# path=path-of-do-file-as-character-object, | |
# tempPath=temp-folder-path-as-character-object) | |
# | |
# A log file is created in the same folder as the .do file | |
# | |
# Because Stata is stupid, dynamically create a temporary batch file. | |
# The batch file contains 3 lines |
repos <- "http://cran.us.r-project.org" | |
if (!require(data.table)) {install.packages("data.table", dependencies=TRUE, repos=repos)} | |
require(data.table) | |
url <- "http://www.unitedstateszipcodes.org/zip_code_database.csv" | |
zip_code_database <- fread(url, | |
colClasses=c(rep("character", 9), | |
rep("numeric", 2), | |
rep("character", 2), | |
rep("integer", 2), | |
rep("character", 1)), |
# .timeStart <- Sys.time() # Defined at start of Rmd | |
list(timeStart = ifelse(exists(".timeStart"), format(.timeStart), NA), | |
timeEnd = Sys.time(), | |
timeElapsed = ifelse(exists(".timeStart"), | |
format(Sys.time() - .timeStart, format=difftime), | |
NA), | |
Sys.info = Sys.info(), | |
sessionInfo = sessionInfo()) |
# History files | |
.Rhistory | |
# Example code in package build process | |
*-Ex.R | |
# R data files from past sessions | |
.Rdata | |
# RStudio files |