NSE Arguments in functions calling plotly raise an error
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- R
- Estrellas
- 2.7k
- Forks
- 641
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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).
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el problema con el ejemplo proporcionado nse_arg_raises_error y, después, sigue plotly:::eval_attr hasta lazyeval:::clone_env y la llamada a base:::as.list.environment. Comprueba cómo la ruta NSE de plotly gestiona un entorno de función que contiene un argumento NSE sin usar. Se considera completado cuando la llamada demostrada a plot_ly ya no produce el error as.list.environment; el payload no menciona ningún archivo de prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- r
- Área
- data-visualization
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100