Typically, you remove NULL items in a flat list with
ll <- list( 1, 2, NULL, 3 ) ll <- ll[ ! sapply(ll, is.null) ]
If you do not know the structure in advance, this is an obvious case to combine this solution with a recursive function:
removeNullRec <- function( x ){ x <- x[ !sapply( x, is.null ) ] if( is.list(x) ){ x <- lapply( x, removeNullRec) } return(x) } removeNullRec(tmp) [[1]] [[1]][[1]] [[1]][[1]][[1]] [1] 2 9 10 [[1]][[2]] [1] 1 3 4 6 [[2]] [1] 7
Edit
It is always helpful to rephrase the problem as simple as possible. From your comments, I realized that (regardless of the appearance of NULL elements), you want to replace each element containing only one child with the child itself. There is also another case that should be considered then: two sister sheets may be NULL . So let's start with a slightly more complex example:

tree <- list( list( list( list( list( NULL, NULL ), list( NULL, NULL ) ), 7 ), list( list( list( c(1,2), NULL ), c(3,4) ))))
This isolated problem for a flat tree, of course, is also better solved by applying a recursive approach:
flatTreeRec <- function( x ){ if( is.list(x) ){
And, of course, you can directly combine these two functions to avoid the stress of your stack twice:
removeNullAndFlatTreeRec <- function( x ){ x <- x[ !sapply( x, is.null ) ] if( is.list(x) ){ x <- lapply( x, removeNullRec) x <- x[ sapply( x, length ) > 0 ] if( length(x) == 1 ){ x <- x[[1]] } } return(x) } removeNullAndFlatTreeRec( tree )