Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flipPlots
Type: Package
Title: Creates Plots
Version: 1.3.8
Version: 1.3.9
Author: Displayr <opensource@displayr.com>
Maintainer: Displayr <opensource@displayr.com>
Description: Wrappers for various plot types.
Expand Down
2 changes: 1 addition & 1 deletion R/sankeydiagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ SankeyDiagram <- function(data = NULL, links.and.nodes = NULL, output.data.only

getNodeGroups <- function(type, links)
{
num.nodes <- length(unique(unlist(links$source, links$target)))
num.nodes <- length(unique(c(unlist(links$source), unlist(links$target))))
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly addresses the R 4.5.0 compatibility issue. The original unlist(links$source, links$target) was invalid syntax - unlist() takes a single list argument, not multiple arguments. Using c(unlist(links$source), unlist(links$target)) properly concatenates the unlisted vectors before finding unique values.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it broken before? Does it fix a bug that the user would have noticed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In R 4.4.2 (which we currently use), there's no error but when we migrate to R 4.5.0 an error will be thrown when the user uses the link.color = "Last variable"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it working before, i.e. links$target was used? The fix looks fine to me, just curious that it wasn't noticed as a bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So num.nodes is being used to initialize the vector, but R is flexible with vector sizing, i.e. you can index beyond the vector length, so there was no bug I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I reran the Standard R tests, and there are no diffs so I guess its not that important that num.nodes is set correctly, but it does make debugging a bit confusing and is probably a bit more inefficient

grps <- rep(NA, num.nodes)
gval <- rep(NA, num.nodes)

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-sankeydiagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ datText <- structure(list(Q1_Gender = structure(c(2L, 2L, 1L, 1L, 2L, 2L,
test_that("Many categories",
{
expect_error(SankeyDiagram(datText), NA)
expect_error(SankeyDiagram(datText, link.color = "Last variable"), NA)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not clear to me how this tests the bug (I'm not familiar with the code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the CI test results (which are using R 4.5.0), the test fails on the first commit. In terms of the code, the error is in getNodeGroups() which is called at line 132 of sankeydiagram.R and is only called when the link.color is "Last variable" or "First variable"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks.

})

dat.longnames <- structure(list(`D3 - Gender` = structure(c(2L, 1L, 2L, 2L, 2L,
Expand Down