plotly / plotly/plotly.R

plotly failures with dev rlang

オープン
#2,488 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
R
スター
2.7k
フォーク
641
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この失敗は tests/testthat/test-ggplot-legend.R でカバーされており、guide のタイトルは ggplotly.R の 1071-1072 行付近で組み立てられています。まず dev 版の rlang で失敗しているテストを実行し、guide の順序がどのように決定されるかを調べてください。更新された rlang の下で、legend title のテストが決定的な順序でパスすれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
r
領域
data-visualization, testing
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。