NSE Arguments in functions calling plotly raise an error
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- R
- Estrelas
- 2.7k
- Forks
- 641
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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).
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Reproduza o problema com o exemplo fornecido nse_arg_raises_error e, em seguida, rastreie plotly:::eval_attr até lazyeval:::clone_env e a chamada para base:::as.list.environment. Verifique como o caminho NSE do plotly lida com um ambiente de função que contém um argumento NSE não utilizado. A tarefa estará concluída quando a chamada plot_ly demonstrada não gerar mais o erro as.list.environment; o payload não nomeia nenhum arquivo de teste.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- r
- Domínio
- data-visualization
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100