# https source.R


## ---------------------------------------------##
##                 SHORT FORM                   ##
## ---------------------------------------------##

  library(RCurl)

  # source utils from github repo
  urls <- c("https://raw.github.com/rsaporta/pubR/gitbranch/utilsRS_pub.r")
  eval(parse(text=getURL(urls, followlocation=TRUE, cainfo=system.file("CurlSSL", "cacert.pem", package="RCurl"))), 
       envir=environment())
## ---------------------------------------------##




## ---------------------------------------------##
##                 LONG FORM                    ##
## ---------------------------------------------##
  library(RCurl)

  # list of all https URLs to source
  urls <- c(
    "https://raw.github.com/rsaporta/pubR/gitbranch/utilsRS_pub.r",
    "https://raw.github.com/rsaporta/pubR/gitbranch/testGitSource.R"
  ) 
  
  # source the https urls
  eval(parse(text=getURL(urls, followlocation=TRUE, cainfo=system.file("CurlSSL", "cacert.pem", package="RCurl"))), 
       envir=environment())
## ---------------------------------------------##





## ---------------------------------------------##
##                 FUNC FORM                    ##
##               FOR SOURCING URLS              ##
##       note the difference in envir=(.)       ##
##                                              ##
## ---------------------------------------------##

source.url <- function(...) {
 # load package
 require(RCurl)

 urls <- list(...)
 eval(parse(text=getURL(urls, followlocation=TRUE, cainfo=system.file("CurlSSL", "cacert.pem", package="RCurl"))),
      envir=parent.frame(1))
}
## ---------------------------------------------##



###################################################################################################
##                                                                                               ##
##  REFERENCES:                                                                                  ##
##                                                                                               ##
##   Modified based on code from                                                                 ##
##     http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github  ##
##     https://github.com/gimoya/theBioBucket-Archives/blob/master/R/Functions/source_https.R    ##
##                                                                                               ##
###################################################################################################
