[R] Line Directives in Sweave Document

Iris Simmons |kw@|mmo @end|ng |rom gm@||@com
Wed Jun 28 07:39:19 CEST 2023


Hello,


I'm trying to demonstrate the behaviour of my R package and how line
directives change that behaviour. So I've got an R chunk like this:

<<keep.source=TRUE>>=
{
#line 1 "file1.R"
    fun <- function() {
        pkg::fun()
    }


#line 1 "file2.R"
    fun()
}
@

but when it is rendered, the line directives do not appear:

> {
+     fun <- function() {
+         pkg::fun()
+     }
+
+
+     fun()
+ }

I tried faking a line directive by writing it twice:

<<keep.source=TRUE>>=
{
 #line 1 "file1.R"
#line 1 "file1.R"
    fun <- function() {
        pkg::fun()
    }


 #line 1 "file2.R"
#line 1 "file2.R"
    fun()
}
@

but then the rendered fake line directive looks bad because it's out
by one space so if it is copy-pasted, it wouldn't actually function as
shown.

So is there an option I can set to have the line directives displayed,
or something else I can change to get it working? Thank you!



More information about the R-help mailing list