Skip to content

Instantly share code, notes, and snippets.

@jgilfillan
Created August 19, 2015 03:52
Show Gist options
  • Save jgilfillan/8f222338b448d2d6536e to your computer and use it in GitHub Desktop.
Save jgilfillan/8f222338b448d2d6536e to your computer and use it in GitHub Desktop.
R include to be run at the top of each R script.
###################################################################################################
#
# Descr: This is a standard header script to be run at the beginning of each R script
# It loads the standard packages and a password prompt function
# Usage: At the top of the r script, place the following text:
# source("[PATH TO RHeader.r]\\RHeader.r")
# Author: Josh Gilfillan
# Date: 20150326
#
###################################################################################################
# define vector of variables to load
packagesToLoad <- c("ggplot2", "dplyr", "tidyr","stringr", "RODBC", 'ROracle', 'RSQLite', 'pander')
# now load the packages
lapply(packagesToLoad, library, character.only=T)
remove('packagesToLoad')
############
# Functions
############
# call function to get prompted for password. NOTE! password will be visible in log
# from http://stackoverflow.com/a/3104339
getPass<-function(){
require(tcltk);
wnd<-tktoplevel();tclVar("")->passVar;
#Label
tkgrid(tklabel(wnd,text="Enter password:"));
#Password box
tkgrid(tkentry(wnd,textvariable=passVar,show="*")->passBox);
#Hitting return will also submit password
tkbind(passBox,"<Return>",function() tkdestroy(wnd));
#OK button
tkgrid(tkbutton(wnd,text="OK",command=function() tkdestroy(wnd)));
#Wait for user to click OK
tkwait.window(wnd);
password<-tclvalue(passVar);
return(password);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment