-
-
Save lee-dohm/3138082 to your computer and use it in GitHub Desktop.
Rscript discovery & reloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rscript.stack <- function() | |
{ | |
# Returns the stack of Rscript files. | |
# | |
# Returns: | |
# Stack of files. | |
Filter(Negate(is.null), lapply(sys.frames(), function(x) x$ofile)) | |
} | |
rscript.current <- function() | |
{ | |
# Returns the path of the current file. | |
# | |
# Returns: | |
# Path to the current file. | |
stack <- rscript.stack() | |
as.character(stack[length(stack)]) | |
} | |
rscript.reloader <- function(func.name, notify=TRUE) | |
{ | |
# Creates a function in the top environment to reload the current script. | |
# | |
# Args: | |
# func.name: Name for the reloader function to take. | |
# notify: Prints a notification of what the reloader function will do when called. | |
func.name <- as.character(func.name) | |
path <- rscript.current() | |
if (notify) | |
{ | |
cat(paste('Invoking ', func.name, '() will source ', path, ' in globalenv().\n', sep='')) | |
} | |
reloader <- function() | |
{ | |
source(path, local=globalenv()) | |
} | |
assign(func.name, reloader, envir=globalenv()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment