error while installing github package and internal server error when runnig help() function

106 Views Asked by At

I am trying to install the brainconn package. I do not know whether something went wrong during installation, but I used the following options:

remotes::install_github("sidchop/brainconn", force = TRUE,
build_vignettes = TRUE, build = FALSE)

When I run

library(brainconn)
x <- example_unweighted_undirected
brainconn(atlas ="schaefer300_n7", conmat= as.data.frame(x), node.size = 3, view="ortho")

this returns the following error:

Error in `handlers[[1L]]()`:
! No layout function defined for objects of class <matrix>

and moreover, after installation, by running the help() of function with ?brainconn I can see image

enter image description here

I cannot understand what it is going wrong. Can anyone suggest some workaround? Thanks

2

There are 2 best solutions below

9
VonC On

That was mentioned in sidchop/brainconn issue 27, and supposed to be fixed with PR 28:

Fix matrix data error

RoxygenNote: 7.2.3 use as.data.frame(conmat) instead of as.matrix(conmat)

But, as you have seen, it is not enough.

Note that issue 31 reports a similar problem, on macOS 13.6.1 with R 4.3.1.

I have just upgraded from Catalina to Ventura, with new R and RStudio installations. I believe all dependencies are present and freshly installed.

So the platform/OS might be important.


From the code alone (brainconn.R):

  • The function attempts to convert the conmat parameter to a matrix using as.matrix(conmat). So, it should accept a data frame or a matrix, and it will convert it to a matrix internally if it is not already one.
  • It checks if the matrix is symmetric using isSymmetric.matrix(conmat). If the matrix is symmetric, it sets directed <- FALSE; otherwise, directed <- TRUE. That influences whether the function expects to plot undirected or directed edges.
  • If all.nodes is FALSE, it will only include nodes with edges. That is done by checking each row and column in the conmat for non-zero values.
  • It allows for thresholding the conmat using the thr and uthr parameters to exclude edges below or above certain values.

So make sure that:

  • the conmat is of the correct dimensions, corresponding to the number of regions in the atlas.
  • the matrix should be correctly formatted as either a symmetric matrix for undirected graphs or a non-symmetric matrix for directed graphs.
  • the matrix values should be appropriate for the type of graph they are plotting (binary for unweighted, numerical values for weighted).
  • all necessary dependencies, especially ggraph, cowplot, grid, and OpenImageR, are correctly installed and loaded.
  • the atlas provided (either one of the included atlases or a custom atlas) is correctly formatted.
1
Pain On

try converting your connectivity matrix (as.data.frame(x)) into a numeric matrix using as.matrix().

library(brainconn)

x <- example_unweighted_undirected conn_matrix <- as.matrix(as.data.frame(x))

brainconn(atlas = "schaefer300_n7", conmat = conn_matrix, node.size = 3, view = "ortho")

This ensures that the input to brainconn is a numeric matrix.