Skip to content

Conversation

@chschan
Copy link
Contributor

@chschan chschan commented Sep 8, 2025

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an error in the flipPlots package that occurs due to stricter argument checking introduced in R 4.5.0. The fix addresses an issue with the unlist() function call in the getNodeGroups() function that was using incorrect syntax.

  • Fixed incorrect unlist() syntax that fails under R 4.5.0's stricter checking
  • Added test coverage for the "Last variable" link color option
  • Incremented package version to 1.3.9

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
R/sankeydiagram.R Fixed unlist() function call to use proper syntax with c()
tests/testthat/test-sankeydiagram.R Added test case for "Last variable" link color option
DESCRIPTION Updated package version from 1.3.8 to 1.3.9

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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

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.

Copy link
Contributor

@JustinCCYap JustinCCYap left a comment

Choose a reason for hiding this comment

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

LGTM

@chschan chschan merged commit c8865ac into master Sep 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants