plotly / plotly/plotly.R

NSE Arguments in functions calling plotly raise an error

Đang mở
#2,249 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
R
Star
2.7k
Fork
641
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện vấn đề bằng ví dụ nse_arg_raises_error được cung cấp, sau đó lần theo plotly:::eval_attr đến lazyeval:::clone_env và lệnh gọi base:::as.list.environment. Kiểm tra cách đường dẫn NSE của plotly xử lý một môi trường hàm chứa một đối số NSE không được sử dụng. Được xem là hoàn tất khi lệnh gọi plot_ly được minh họa không còn phát sinh lỗi as.list.environment; payload không nêu tên tệp kiểm thử nào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
r
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.