如何打印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
相关产品推荐
相关产品推荐

