-
-
Notifications
You must be signed in to change notification settings - Fork 880
Open
Labels
Description
It seems that code executed in chunks sets the srcref attribute differently than code executed in the console.
Please consider the following .Rmd file.
---
title: "Srcref"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Srcref}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = ""
)
```
The following does not work as expected.
```{r}
options(keep.source = TRUE)
myfun <- function(x) {
substitute(x)
}
x <- myfun({1 + 2})
x
attributes(x)
attributes(myfun)
```
It should produce
```
options(keep.source = TRUE)
myfun <- function(x) {
substitute(x)
}
x <- myfun({1 + 2})
x
{
1 + 2
}
attributes(x)
$srcref
$srcref[[1]]
{
$srcref[[2]]
1 + 2
$srcfile
$wholeSrcref
x <- myfun({1 + 2}
attributes(myfun)
$srcref
function(x) {
substitute(x)
}
```
The result is:
This may also be the reason why some examples in "Advanced R" are not displayed correctly. Consider for example the last chunk in 6.2.1 Function components or the first chunk in 20.2.3 Gotcha: function().
