A useful function for exploratory work or when coding. Takes a list as an argument and prints a glimpse of the data contained in each list element and the dimensions of each list element. If the list contains more than 5 list elements, only the first 5 elements are printed to console with no warning. The function will print a maximum of 10 values if the list element is a vector and 10 rows and 5 columns if the list element is a matrix.
inspect_list(x)
A list of vectors or matrices
NOTE: There are currently no checks built in to handle a list of lists. In this case, everything in the sublists will be printed with no checks or warnings.
x <- list(
matrix(runif(100), nrow = 20, ncol = 5),
matrix(runif(100), nrow = 10, ncol = 10)
)
inspect_list(x)
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.47864607 0.1868524 0.1446403 0.457414 0.866047
#> [2,] 0.19042595 0.6321412 0.2953546 0.838915 0.107304
#> [3,] 0.14778547 0.4818266 0.0985435 0.919180 0.511697
#> [4,] 0.38813490 0.0525571 0.0215280 0.517784 0.948044
#> [5,] 0.84316295 0.2175217 0.7743863 0.173941 0.191609
#> [6,] 0.71719693 0.8557328 0.0211413 0.527158 0.105366
#> [7,] 0.19895989 0.6928056 0.2897281 0.844000 0.102594
#> [8,] 0.22576954 0.9676762 0.5602998 0.628241 0.789387
#> [9,] 0.00431341 0.3139007 0.3800631 0.222306 0.773410
#> [10,] 0.92898909 0.0293963 0.1105779 0.931826 0.220949
#>
#> [[1]][[2]]
#> [1] 20 5
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.5339059 0.0155854 0.6884118 0.0292570 0.943220
#> [2,] 0.0326276 0.6858234 0.1418802 0.6515156 0.582170
#> [3,] 0.2500174 0.5876167 0.0288431 0.6095190 0.228229
#> [4,] 0.6539946 0.3204716 0.6449449 0.0475747 0.602674
#> [5,] 0.3115852 0.5605098 0.9901933 0.8381285 0.478966
#> [6,] 0.3088339 0.6187301 0.8731238 0.5527619 0.458521
#> [7,] 0.7492686 0.1797859 0.8765811 0.8293296 0.913431
#> [8,] 0.0457543 0.6423080 0.9250502 0.6199260 0.278512
#> [9,] 0.5321888 0.1680474 0.5554681 0.5783548 0.371437
#> [10,] 0.6197225 0.6325408 0.5746117 0.3411806 0.507406
#>
#> [[2]][[2]]
#> [1] 10 10
#>
#>