【发布时间】:2022-02-04 03:41:17
【问题描述】:
在 for 循环中尝试显示时,我的 visNetwork 根本不显示。在常规的 R 脚本中,我使用 print 函数,它工作得很好,但它在 R Markdown 文档中不起作用。
这是一个(希望是)可重现的例子:
---
title: "I want my beautiful networks back!"
---
# First example that works
```{r}
require(visNetwork, quietly = TRUE)
# minimal example
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
vn <- visNetwork(nodes, edges, width = "100%")
vn # Or print(vn)
```
# When does it not work?
## In a for loop
```{r}
for (i in 1) vn
```
## In a for loop + using print
This will display the network in the Viewer.
```{r}
for (i in 1) print(vn)
```
## And also in functions
Same remark...
```{r}
foo <- function(x) print(x)
foo(vn)
```
我使用的是 Rstudio 版本 1.1.383 和
这是sessionInfo()的结果
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
other attached packages:
[1] visNetwork_2.0.2
【问题讨论】:
标签: r visnetwork