Skip to content

[Bug]: bootstrap in network analysis cannot work well #3125

@alextaoo

Description

@alextaoo

JASP Version

0.19.3

Commit ID

No response

JASP Module

Network

What analysis are you seeing the problem on?

No response

What OS are you seeing the problem on?

Windows 11

Bug Description

该分析意外终止。

Error in .extractErrorMessage(e): length(error) = 1 is not TRUE

Stack trace
.networkAnalysisBootstrap(mainContainer, network, options)

.networkAnalysisComputeBootstrap(bootstrapContainer, network, options)

tryCatch({
jaspBase::.suppressGrDevice({
for (nm in names(allNetworks)) {
bootstrapResult[[nm]] <- bootnet::bootnet(data = allNetworks[[nm]], nBoots = options[['bootstrapSamples']], type = options[['bootstrapType']], nCores = nCores, statistics = c('edge', 'strength', 'closeness', 'betweenness'), labels = options[['variables']])
}
})
}, error = function(e) bootstrapContainer$setError(.extractErrorMessage(e)))

tryCatchList(expr, classes, parentenv, handlers)

tryCatchOne(expr, names, parentenv, handlers[[1]])

value[3]

bootstrapContainer$setError(.extractErrorMessage(e))

private$jaspObject$setError(x)

.extractErrorMessage(e)

stopifnot(length(error) = 1)

要获得有关此问题的帮助,请在以下位置报告上述消息:https://jasp-stats.org/bug-reports

Expected Behaviour

should work well

Steps to Reproduce

This error message indicates an issue in the R code related to the networkAnalysisBootstrap and related functions. The key error message is length(error) = 1 is not TRUE which occurs within the stopifnot statement in the extractErrorMessage function (or a function that calls it).

Here's a breakdown of what might be going wrong:

1. extractErrorMessage function

The extractErrorMessage function likely expects the error object (which presumably represents an error that occurred earlier) to have a length of 1. But for some reason, when this check is made, the length of error is not 1, and thus the stopifnot condition fails and throws the error you're seeing.

2. Error handling in tryCatch

The tryCatch block is set up to handle errors that occur when running the bootnet::bootnet function. When an error happens during the execution of that bootnet call (for example, if there's an issue with the input data allNetworks[[nm]], incorrect specification of nBoots, type, etc., or a problem within the bootnet function itself), the error handler is supposed to call bootstrapContainer$setError(.extractErrorMessage(e)). However, since the extractErrorMessage function has the length check issue, it fails to handle the error gracefully.

3. Possible causes of incorrect error length

  • Multiple errors combined: Perhaps multiple errors are somehow being bundled together and passed to extractErrorMessage instead of a single error object, which would violate the expected length condition.
  • Incorrect error object creation: There could be a problem in how the error object is created or modified earlier in the code flow before it reaches the extractErrorMessage function. Maybe it's being initialized or populated in an unexpected way that results in it having a length other than 1.

4. Suggested steps for debugging

  • Check the bootnet call: Look closely at the input data (allNetworks), the values of nBoots, bootstrapType, nCores, and other parameters passed to bootnet::bootnet. Make sure they are all correctly specified and that the data is in the expected format. There could be something wrong with these inputs that is causing an error that then gets mishandled later.
  • Print the error object: Add some debugging statements to print the error object right before it's passed to extractErrorMessage in the tryCatch block. This can help you see what's actually in the error object and if it's indeed not in the expected format. For example, you could add print(e) just before bootstrapContainer$setError(.extractErrorMessage(e)) in the tryCatch block.
  • Check the extractErrorMessage function: Examine the extractErrorMessage function itself to see if there are any other parts of the code within it that could be modifying the error object's length or if there's an incorrect assumption about the structure of the error object that it's supposed to receive.

Overall, the error message points to a problem in the error handling and assumptions about the error object's structure in the context of the network analysis code you're working with.

Log (if any)

No response

More Debug Information

No response

Final Checklist

  • I have included a screenshot showcasing the issue, if possible.
  • I have included a JASP file (zipped) or data file that causes the crash/bug, if applicable.
  • I have accurately described the bug, and steps to reproduce it.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions