Learn R Programming

this.path (version 1.2.0)

LINENO: Line Number of Executing Script

Description

Get the line number of the executing script.

Usage

LINENO()

Arguments

Value

An integer, NA_integer_ if the line number cannot be determined.

Examples

Run this code
FILE <- tempfile(fileext = ".R")
writeLines(c(
    "LINENO()",
    "LINENO()",
    "# LINENO() respects #line directives",
    "#line 1218",
    "LINENO()"
), FILE)


# previously used:
#
# ```
# source(FILE, echo = TRUE, verbose = FALSE,
#     max.deparse.length = Inf, keep.source = TRUE)
# ```
#
# but it echoes incorrectly with #line directives.
# `source2()` echoes correctly!
this.path:::source2(FILE, echo = TRUE, verbose = FALSE,
    max.deparse.length = Inf, keep.source = TRUE)
unlink(FILE)

Run the code above in your browser using DataLab