Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_network example failure: class conditions and incompatibility with latest igraph #8

Open
kyleam opened this issue Aug 30, 2022 · 0 comments

Comments

@kyleam
Copy link

kyleam commented Aug 30, 2022

Thanks for your work on this package.

When I try to build with R 4.1 from GERGM's master (ffb67f7), I see a failure related to a non-scalar condition:

* checking examples ... ERROR
Running examples in ‘GERGM-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: plot_network
> ### Title: Plots of value-edged networks.
> ### Aliases: plot_network
>
> ### ** Examples
>
> set.seed(12345)
> sociomatrix <- matrix(rnorm(400,0,20),20,20)
> colnames(sociomatrix) <- rownames(sociomatrix) <- letters[1:20]
> plot_network(sociomatrix)
 ----------- FAILURE REPORT --------------
 --- failure: the condition has length > 1 ---
 --- srcref ---
:
 --- package (from environment) ---
GERGM
 --- call from context ---
plot_network(sociomatrix)
 --- call from argument ---
if (class(sociomatrix) != "matrix" & class(sociomatrix) != "data.frame") {
    stop("You must provide the network as a numeric matrix.")
}
 --- R stacktrace ---
where 1: plot_network(sociomatrix)
 --- value of length: 2 type: logical ---
[1] FALSE  TRUE
 --- function from context ---

If I resolve that and a related issue with the following patch...

diff --git a/R/plot_network.R b/R/plot_network.R
index 0569e38..63f7fad 100644
--- a/R/plot_network.R
+++ b/R/plot_network.R
@@ -55,7 +55,7 @@ plot_network <- function(sociomatrix,

   par(mar = c(1,0,1,0))
   # check input
-  if (class(sociomatrix) != "matrix" & class(sociomatrix) != "data.frame") {
+  if (!inherits(sociomatrix, c("matrix", "data.frame"))) {
     stop("You must provide the network as a numeric matrix.")
   }

@@ -90,8 +90,7 @@ plot_network <- function(sociomatrix,
     }

     # check optional input
-    if (class(comparison_network) != "matrix" &
-       class(comparison_network) != "data.frame") {
+    if (!inherits(comparison_network, c("matrix", "data.frame"))) {
       stop("You must provide the network as a numeric matrix.")
     }

... I hit into another error in the same example:

❯ checking examples ... ERROR
  Running examples in ‘GERGM-Ex.R’ failed
  The error most likely occurred in:

  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: plot_network
  > ### Title: Plots of value-edged networks.
  > ### Aliases: plot_network
  >
  > ### ** Examples
  >
  > set.seed(12345)
  > sociomatrix <- matrix(rnorm(400,0,20),20,20)
  > colnames(sociomatrix) <- rownames(sociomatrix) <- letters[1:20]
  > plot_network(sociomatrix)
  Error in igraph::layout_with_fr(net, weights = igraph::E(net)$weight) :
    At core/layout/fruchterman_reingold.c:401 : Weights must be positive for Fruchterman-Reingold layout. Invalid value
  Calls: plot_network -> <Anonymous>
  Execution halted

That failure is with igraph 1.3.4, which was published 2022-07-19. If I try with 1.3.3, I see the same failure. The failure goes away with 1.3.2.

Perhaps igraph got stricter in its checks and the example just needs to be updated to use more realistic input?

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

No branches or pull requests

1 participant