Skip to content

Instantly share code, notes, and snippets.

@rafalcode
Forked from christophergandrud/source_lines.R
Created June 23, 2023 22:12
Show Gist options
  • Save rafalcode/a1796370a2ccf06b8167f2a27dcf00e7 to your computer and use it in GitHub Desktop.
Save rafalcode/a1796370a2ccf06b8167f2a27dcf00e7 to your computer and use it in GitHub Desktop.
Source specific lines from a file in R
#' Source specific lines in an R file
#'
#' @param file character string with the path to the file to source.
#' @param lines numeric vector of lines to source in \code{file}.
source_lines <- function(file, lines){
source(textConnection(readLines(file)[lines]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment