You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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().
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
It seems that code executed in chunks sets the
srcref
attribute differently than code executed in the console.Please consider the following
.Rmd
file.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().
The text was updated successfully, but these errors were encountered: