LINENO | R Documentation |
Get the line number of the executing expression.
LINENO(n = 0, envir = parent.frame(n + 1),
matchThisEnv = getOption("topLevelEnvironment"),
srcfile = if (n) sys.parent(n) else 0)
n , envir , matchThisEnv , srcfile |
See |
LINENO()
only works if the expressions have a
\codelink2base:srcfilesrcref.
Scripts run with \Rscriptlink do not store their srcref
, even when
\codelink3base:optionsgetOption("keep.source") is TRUE
.
For \sourcelink and \syssourcelink, make sure to supply argument
keep.source = TRUE
directly, or set options \stringkeep.source and
\stringkeep.source.pkgs to TRUE
.
For \debugSourceinRStudiolink, it has no argument keep.source
, so set
option \stringkeep.source to TRUE
before calling.
For \compilerloadcmplink, the srcref
is never stored for the compiled
code, there is nothing that can be done.
For \utilsSweavelink, the srcref
is never stored, there is nothing
that can be done.
For \knitrknitlink, the srcref
is never stored, there is nothing that
can be done. I am looking into a fix.
For \targetslink, set option \stringkeep.source to TRUE
before
calling associated functions.
For \boxuselink, \plumberplumblink, \shinyrunApplink, and
\testthatsourcefilelink, the srcref
is always stored.
integer; NA_integer_
if the line number is not found.
You can get a more accurate line number by wrapping LINENO()
in
braces:
{ LINENO() }
FILE.R <- tempfile(fileext = ".R")
writeLines(c("
LINENO()
LINENO()
## LINENO() respects #line directives
#line 15
LINENO()
#line 1218
cat(sprintf('invalid value %d at %s, line %d\\n',
-5, try.this.path(), LINENO()))
"), FILE.R)
if (getRversion() >= "4.3.0") {
source(FILE.R, echo = TRUE, verbose = FALSE,
max.deparse.length = Inf, keep.source = TRUE)
} else {
this.path:::.source(FILE.R, echo = TRUE, verbose = FALSE,
max.deparse.length = Inf, keep.source = TRUE)
}
unlink(FILE.R)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.