Psi*_*dom 15
您可以查看data.tree包裹.它允许很好地打印嵌套列表,它不需要你编写复杂的功能.这是一个例子:
library(data.tree)
> dt <- FromListSimple(mynestedlist)
> dt
levelName
1 Root
2 ¦--1
3 °--2
4 °--1
Run Code Online (Sandbox Code Playgroud)
这允许您在列表级别进行检查,并且可以将其与此结合使用str以获得列表结构的完整图片.
如果需要,还可以进行一些漂亮的递归:
get_str_recur <- function(x,text2,y){
text <- paste0(text2,"Element[",y,"] is a List of length ",length(x), " --> ")
for (i in (1:(length(x)))){
subs <- x[[i]]
if (is.list(subs)){
get_str_recur(subs,text,i)
}else{
print(paste0(text," Element [",i,"] is a ",class(subs)," of length ",length(subs)))
}
}
}
get_str_recur(mynestedlist,"",0)
#[1] "Element[0] is a List of length 2 --> Element[1] is a List of length 2 --#> Element [1] is a character of length 26"
#[1] "Element[0] is a List of length 2 --> Element[1] is a List of length 2 --> #Element [2] is a character of length 12"
#[1] "Element[0] is a List of length 2 --> Element[2] is a List of length 3 --> #Element[1] is a List of length 3 --> Element [1] is a numeric of length 20"
#[1] "Element[0] is a List of length 2 --> Element[2] is a List of length 3 --> #Element[1] is a List of length 3 --> Element [2] is a numeric of length 1"
#[1] "Element[0] is a List of length 2 --> Element[2] is a List of length 3 --> #Element[1] is a List of length 3 --> Element [3] is a numeric of length 1"
#[1] "Element[0] is a List of length 2 --> Element[2] is a List of length 3 --> #Element [2] is a numeric of length 20"
#[1] "Element[0] is a List of length 2 --> Element[2] is a List of length 3 --> #Element [3] is a numeric of length 20"
Run Code Online (Sandbox Code Playgroud)
这提供了列表树的每个分支的漂亮可视流程图。