This is a simple edit of giraffehere's excellent answer.
For some lists, itβs convenient to print only the heading of a subset of nested objects to print the name of this slot above the output of head ().
Arguments:
USE: printList (mylist, n = 5, hn = 3)
printList <- function(list, n = length(list), hn = 6) { for (item in 1:n) { cat("\n", names(list[item]), ":\n") print(head(list[[item]], hn)) } }
For numerical lists, the output may be more readable if the number of digits is limited to 3, for example:
printList <- function(list, n = length(list), hn = 6) { for (item in 1:n) { cat("\n", names(list[item]), ":\n") print(head(list[[item]], hn), digits = 3) } }
source share