plotly / plotly/plotly.R

plotly failures with dev rlang

Abierto
#2,488 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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

I'm seeing failures for plotly with dev rlang:

  Running ‘testthat.R’
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library("testthat")
  > library("plotly")
  Loading required package: ggplot2
  
  Attaching package: 'plotly'
  
  The following object is masked from 'package:ggplot2':
...
  Expected `legend_title` to match regexp "factor\\(cyl\\)$".
  Actual text:
  ✖ │ factor(cyl)<br />factor(vs)
  
  [ FAIL 2 | WARN 23 | SKIP 63 | PASS 1449 ]
  Deleting unused snapshots: 'ggplot-contour/contour.svg' and
  'ggplot-heatmap/heatmap.svg'
  Error:
  ! Test failures.
  Execution halted

Claude traced this to rlang::hash() producing different hashes in the new version (which was deliberate to fix other stability issues see https://github.com/r-lib/rlang/issues/1681#issuecomment-4267291605):

The chain is:

  1. rlang dev changed hash() values (commit 229db8154 — "Stable hash()"). The NEWS says: "with this version all hash values will now be different". This is intentional for cross-R-version
  stability.
  2. ggplot2's Guides$merge sorts by hash. In Guides$merge(), each guide gets a key {order}_{hash} and then split(pairs, hashes) is called. R's split() returns groups in alphabetical order
  of factor levels. So the final guide order depends on the alphabetical sort of the hash strings.
  3. plotly concatenates guide titles in order. At ggplotly.R:1071-1072:
  legendTitles <- compact(lapply(gdefs, function(g) if (inherits(g, "legend")) g$title else NULL))
  legendTitle <- paste(legendTitles, collapse = br())
  4. The plotly test asserts a specific order (test-ggplot-legend.R:32-33):
  expect_match(legend_title, "^factor\\(vs\\)")   # vs first
  expect_match(legend_title, "factor\\(cyl\\)$")  # cyl last

  With CRAN rlang, the hashes sort as 99_124c... (vs) < 99_4d3... (cyl) → title = factor(vs)<br />factor(cyl).
  With dev rlang, the hashes sort as 99_aefe... (cyl) < 99_ebf7... (vs) → title = factor(cyl)<br />factor(vs).

I've talked to the ggplot2 maintainers and they recommend using the order argument to make guide placement deterministic. Claude also suggests this fix (unverified):

diff --git a/tests/testthat/test-ggplot-legend.R b/tests/testthat/test-ggplot-legend.R
index 9dd92ea..d1d97e5 100644
--- a/tests/testthat/test-ggplot-legend.R
+++ b/tests/testthat/test-ggplot-legend.R
@@ -29,8 +29,8 @@ test_that("Discrete colour and shape get merged into one legend", {
     nms, paste0("(", d$vs, ",", d$cyl, ")")
   )
   legend_title <- info$layout$legend$title$text
-  expect_match(legend_title, "^factor\\(vs\\)")
-  expect_match(legend_title, "factor\\(cyl\\)$")
+  expect_match(legend_title, "factor\\(vs\\)")
+  expect_match(legend_title, "factor\\(cyl\\)")
 })

As a heads up, I'm planning to release this rlang update within the next two weeks.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

El fallo está cubierto por tests/testthat/test-ggplot-legend.R, y los títulos de las guías se ensamblan en ggplotly.R alrededor de las líneas 1071-1072. Empieza ejecutando el test que falla con la versión dev de rlang e inspecciona cómo se determina el orden de las guías. Se considera terminado cuando el test del título de la leyenda pasa con un orden determinista usando la versión actualizada de rlang.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
r
Área
data-visualization, testing
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.