Skip to content

@klmr /rs.r
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A versatile re-source file function for R
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)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.