datastorm-open / visNetwork

R package, using vis.js library for network visualization
Other
545 stars 125 forks source link

Error running visNetwork test: could not find function "%>%" #403

Open mr-c opened 3 years ago

mr-c commented 3 years ago
BEGIN TEST get_coefficients_transformation.R

R version 4.0.4 (2021-02-15) -- "Lost Library Book"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> # transformation in vis.js
> x <- numberOfNodes <- 1:1000
> y <- 12.662 / (numberOfNodes + 7.4147) + 0.0964822
> # var factor = Math.min(this.canvas.frame.canvas.clientWidth / 600, this.canvas.frame.canvas.clientHeight / 600);
> # zoomLevel *= factor;
> plot(x, y)
> 
> require(nleqslv)
Loading required package: nleqslv
> 
> x = c(2,  42, 100)
> y= c(0.02, 0.77, 1.3)
> 
> f <- function(par) {
+   
+   fval <- numeric(length(par))
+   v1 <- par[1]
+   v2 <- par[2]
+   v3 <- par[3]
+   
+   fval[1] = (v1 / (x[1] + v2) + v3) - y[1]
+   fval[2] = (v1 / (x[2] + v2) + v3) - y[2]
+   fval[3] = (v1 / (x[3] + v2) + v3) - y[3]
+   
+   fval
+ }
> nleqslv(c(-100,25, 5), f, control = list(maxit = 5000))
$x
[1] -232.622349   91.165919    2.516861

$fvec
[1] -1.373522e-11 -1.237122e-11 -7.940315e-12

$termcd
[1] 1

$message
[1] "Function criterion near zero"

$scalex
[1] 1 1 1

$nfcnt
[1] 41

$njcnt
[1] 2

$iter
[1] 32

> 
> numberOfNodes <- 1:10000
> y <- -232.622349 / (numberOfNodes + 91.165919)  +2.516861
> plot(numberOfNodes, y)
> 
BEGIN TEST highlight_combinaison.R

R version 4.0.4 (2021-02-15) -- "Lost Library Book"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> # simple nodes, passing some information individually
> nodes <- data.frame(id = 1:5, color = c("blue", NA, "green", NA, NA))
> 
> edges <- data.frame(from = trunc(runif(5)*(5-1))+1,
+                     to = trunc(runif(5)*(5-1))+1)
> 
> visNetwork(nodes, edges) %>% 
+   visOptions(highlightNearest = list(enabled = T, degree = 1, hover = F))
Error in visNetwork(nodes, edges) %>% visOptions(highlightNearest = list(enabled = T,  : 
  could not find function "%>%"
Execution halted
SangeetM commented 3 years ago

load tidyverse which indirectly call magrittr which is the required package for using %>%

stragu commented 2 years ago

@mr-c : to add to @SangeetM 's comment, you can also directly use library(magrittr)without needing to load the whole tidyverse, it would be lighter and faster.

Alternatively, if you upgrade to R 4.1, you could use the new native pipe instead, without needing to load anything extra: |>

I think this issue can be closed, unless it is a request to import the magrittr pipe at the time of loading visNetwork.