public
Created

A versatile re-source file function for R

  • Download Gist
rs.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
rs <- function(...) {
# Re-source a source file. Usage:
#
# rs()
# rs(filename)
# rs(filename, line)
# rs(filename, from, to)
# rs(line)
# rs(from, to)
 
args <- list(...)
 
if (is.character(args[[1]])) {
attr(rs, 'file') <<- args[[1]]
args[[1]] <- NULL
}
 
file <- attr(rs, 'file')
 
if (length(args) == 0) {
source(file)
}
else if (length(args) == 1) {
from <- args[[1]]
source(pipe(sprintf('sed -n %dp %s', from, file)))
}
else if (length(args) == 2) {
from <- args[[1]]
to <- args[[2]]
source(pipe(sprintf('sed -n %d,%dp %s', from, to, file)))
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.