Skip to contents

# Source Lines from a File

Source: `R/source_lines.R`
`source_lines.Rd`

Sources specific lines from a file

## Usage

    source_lines(file, lines, ...)

## Arguments

file

  A character string giving the path to the file to be sourced.

lines

  A numeric vector of line numbers to be sourced.

...

  Additional arguments to be passed to `source`.

## Value

The result of `source`.

## See also

This function is borrowed from a gist by christophergandrud.

## Examples

    test_file <- tempfile(fileext = ".R")
    writeLines(c("# Line 1", "2+2", "# Line 3"), test_file)
    source_lines(test_file, 1:2, echo=TRUE)
    #>
    #> > 2 + 2
    #> [1] 4