NSE Arguments in functions calling plotly raise an error
還沒有人認領這個 Issue。
- 主要語言
- R
- 星號
- 2.7k
- 分支
- 641
- PR 合併指標
- 30 天內沒有已合併 PR
描述
While toying with different NSE approaches I stumbled upon the following behaviour which seems to me like a bug. Any NSE argument (even if not used in plotly) results in an error:
library(plotly)
nse_arg_raises_error <- function(xx) {
mf <- rlang::new_formula(NULL, rlang::ensym(xx), globalenv())
plot_ly(mtcars, x = ~ cyl, y = ~ mpg, type = "scatter",
mode = "markers")
}
nse_arg_raises_error() ## works
nse_arg_raises_error(cyl) ## does not work
#> Error in as.list.environment(x, all.names = TRUE): object 'cyl' not found
This behaviour is unique to plotly, b/c if I leave out the plot_ly call, the error does not happen.
it_is_a_plotly_problem <- function(xx) {
mf <- rlang::new_formula(NULL, rlang::ensym(xx), globalenv())
1 + 1
}
it_is_a_plotly_problem() ## works
#> [1] 2
it_is_a_plotly_problem(cyl) ## also works
#> [1] 2
However, some preliminary debugging shows that the culprit sits (deep) in base:::as.list.environment (which is called from lazyeval:::clone_env, which in turn together with its brethren from lazyeval is responsible for the NSE part in plot_ly)
it_is_a_as_list_environment_issue <- function(xx) {
mf <- rlang::new_formula(NULL, rlang::ensym(xx), globalenv())
cp <- as.list.environment(environment())
1 + 1
}
it_is_a_as_list_environment_issue(cyl)
#> Error in as.list.environment(x, all.names = TRUE): object 'cyl' not found
So basically, when lazyeval:::clone_env copies the function environment which contains an NSE argument this error from within the C code implementation of base::as.list.environment bubbles up.
I am inclined to say that this a feature and not a bug of as.list.environment and the user of it should make sure that environments using it are in fact able to be safely transformed into a list. Thus, I am posting the issue here as it touches the whole NSE strategy of plotly - coming from plotly:::eval_attr (especially since lazyeval is retired in favor of rlang).
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用提供的 nse_arg_raises_error 範例重現問題,然後追蹤 plotly:::eval_attr,直到 lazyeval:::clone_env 以及對 base:::as.list.environment 的呼叫。檢查 plotly 的 NSE 路徑如何處理包含未使用 NSE 引數的函式環境。完成標準是:示範中的 plot_ly 呼叫不再引發 as.list.environment 錯誤;payload 未指定測試檔案。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- r
- 領域
- data-visualization
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100