Skip to content

Instantly share code, notes, and snippets.

@vst
Created February 8, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vst/1765907 to your computer and use it in GitHub Desktop.
Save vst/1765907 to your computer and use it in GitHub Desktop.
My .Rprofile
## Increase the width for wider screens:
options("width"=140)
## Change the prompt:
options(prompt="R> ")
## Set digits to 4 while printing:
options(digits=4)
## Set penalty for scientific notation while printing:
options(scipen=10)
## Use the default CRAN:
repositories = getOption("repos")
repositories["CRAN"] <- "http://cran.r-project.org"
options(repos=repositories)
## Remove the variable. We don't want it be with us all the time:
rm(repositories)
## Configure the X11 graphic options by hooking into the onLoad event
## of grDevices package:
setHook(packageEvent("grDevices", "onLoad"), function(...) {
grDevices::X11.options(width=8,
height=6,
xpos=0,
pointsize=9,
canvas="#DBDEE3")
})
## Define the Golden Ratio. It is sometimes useful for plots etc.:
.GoldenRatio = 1.61803399
##' Retrieves and evaluates a remote R source file. Requires the RCurl
##' package.
##'
##' @param file defines a URL as the remote source file path
##' @param local indicates if the remote source should be evaluated in
##' the environment which calls remoteSource. If FALSE (default),
##' evaluated in the global environment.
##' @param verbose indicates if verbose output should be printed.
##' @param echo indicates if the source should be echoed before
##' evaluation.
##' @return result of evaluating the remote source.
remoteSource <- function(file, local=FALSE, verbose=FALSE, echo=FALSE) {
## Define verbose output method:
.ccat = function (...) {
if (verbose) {
cat(...)
}
}
## We need the RCurl for remote source served over https:
require(RCurl)
## Attempt to get the remote source:
.ccat("Attempting to retrieve the remote source...\n")
csource <- getURL(file)
.ccat("Remote source retrieved...\n")
## Prepare arguments:
.ccat("Parsing the source...\n")
args = list(expr=parse(text=csource))
if (local) {
args = append(args, envir=.GlobalEnv)
}
## Done, evaluate the source:
.ccat("Evaluating the source...\n")
if (echo) {
cat(sprintf("%s\n", csource))
}
return(do.call(eval, args))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment