You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何打印tbl_graph对象的更多行内容?

如何打印tbl_graph对象的更多行内容?

示例代码

library(tidygraph)
library(tibble)
mynodes <- tibble(id = c(1,2,3,4,5,6,7,8,9,10))
myedges <- tibble(from = c(1,1,1,5,2,2,4,8,8,8),
                  to = c(1,2,3,4,3,4,1,2,3,4),
                  power = c(10,10,10,3,3,3,2,2,2,2))
graph = tbl_graph(nodes = mynodes, edges = myedges)

默认打印输出

graph
# A tbl_graph: 10 nodes and 10 edges
#
# A directed multigraph with 5 components
#
# A tibble: 10 × 1
     id
  <dbl>
1     1
2     2
3     3
4     4
5     5
6     6
# ℹ 4 more rows
# ℹ Use `print(n = ...)` to see more rows
#
# A tibble: 10 × 3
   from    to power
  <int> <int> <dbl>
1     1     1    10
2     1     2    10
3     1     3    10
# ℹ 7 more rows
# ℹ Use `print(n = ...)` to see more rows

解决方案

tbl_graph的打印方法支持专门参数控制节点和边的显示行数:

  • 显示所有节点和边:
print(graph, n = Inf, edges_n = Inf)
  • 自定义显示行数(比如显示10个节点和10条边):
print(graph, n = 10, edges_n = 10)
  • 也可以单独激活节点或边对象,用常规tibble打印参数控制:
# 显示所有节点
graph %>% activate(nodes) %>% print(n = Inf)

# 显示所有边
graph %>% activate(edges) %>% print(n = Inf)

内容的提问来源于stack exchange,提问作者sotnik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 02:12:03