Skip to content

fix: fix the incorrect handling of the sample parameter in sample_motifs() and ensure that the default sample.size is integer#1568

Merged
krlmlr merged 5 commits intomainfrom
fix/sample_motifs
Nov 7, 2024
Merged

fix: fix the incorrect handling of the sample parameter in sample_motifs() and ensure that the default sample.size is integer#1568
krlmlr merged 5 commits intomainfrom
fix/sample_motifs

Conversation

@szhorvat
Copy link
Copy Markdown
Member

@krlmlr Please use this fix instead of the one in #1565, which doesn't seem correct. This also fixes a bad default value for the sample.size parameter. Recent igraph errors for non-integer values.

@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Oct 31, 2024

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

R/motifs.R Outdated
#' sample_motifs(g, 3)
sample_motifs <- function(graph, size = 3, cut.prob = rep(0, size),
sample.size = vcount(graph) / 10, sample = NULL) {
sample.size = ceiling(vcount(graph) / 10), sample = NULL) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this default is getting a bit long. could we make it NULL and do the complicated stuff within the function? https://design.tidyverse.org/defaults-short-and-sweet.html#null-default

expect_equal(m5 / m, c(NA, NA, 0.439985332979302, NA, 0.440288166730411, 0.346938775510204, 0.44159753136382, 0.452054794520548, NaN, 0.323076923076923, NaN, 0.347826086956522, NaN, NaN, NaN, NaN))
})

test_that("sample_motifs works", {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
test_that("sample_motifs works", {
test_that("sample_motifs() works", {

g <- make_graph(~ A-B-C-A-D-E-F-D-C-F)
n <- vcount(g)

mc <- sample_motifs(g)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we name the three mc things differently to make them distinct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

motif_count

@krlmlr krlmlr force-pushed the fix/sample_motifs branch from abf9f8b to dca5e2f Compare November 7, 2024 09:32
@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Nov 7, 2024

Thanks!

graph,
size = 3,
cut.prob = rep(0, size),
sample.size = NULL,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm a bit uncomfortable about the default being hidden behind NULL, as the value is actually very relevant during usage, and this default value is completely arbitrary.

IMO the ideal solution would be to force users to provide either sample.size or sample explicitly instead of relying on the default. However, that is a breaking change not suitable for this release.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you please open an issue for this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, the rationale is documented, the defaults are documented, and this will end up having a very low priority for a long time.

https://design.tidyverse.org/defaults-short-and-sweet.html#null-default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can change the interface to make arguments required, even in a lifecycle-friendly way. I think I misread this as a request to put back the inline default.

We could start with a message that is shown if the argument is omitted but would have been relevant.

@aviator-app aviator-app bot added the blocked label Nov 7, 2024
@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Nov 7, 2024

This pull request failed to merge: some required checks failed. After you have resolved the problem, you should remove the blocked pull request label from this PR and then try to re-queue the PR. Note that the pull request will be automatically re-queued if it has the mergequeue label.

Failed checks: Sanitizer

@szhorvat
Copy link
Copy Markdown
Member Author

szhorvat commented Nov 7, 2024

The CI failure is related to rgl. I think Aviator should be overridden and this should be merged.

Either there's a real memory leak in rgl (in which case this should be reported to them, but it's too much work to create a minimal example right now), or it's a LeakSanitizer false positive (in which case we need to add a suppression, which is also annoying and time consuming).

@krlmlr krlmlr merged commit fd1fd9b into main Nov 7, 2024
@krlmlr krlmlr deleted the fix/sample_motifs branch November 7, 2024 13:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants