R for the list s> 3 by a nested hypothetical example that does not work

I could not find a fix for this error. I used to implement workarounds, but I wonder if anyone knows about this, why this happens.

the following returns an error as expected

q <- list()
q[["a"]][["b"]] <- 3
q[["a"]][["c"]] <- 4

However, when I add another level of nesting, I get:

q <- list()
q[["a"]][["b"]][["c"]]<- 3
q[["a"]][["b"]][["d"]] <- 4

"Error in q [[" a "]] [[" b "]] [[" d "]] <- 4: more items added than replaced"

To make this even more confusing, if I add a fourth nested list, I get:

q <- list()
q[["a"]][["b"]][["c"]][["d"]] <- 3
q[["a"]][["b"]][["c"]][["e"]] <- 4

Error in *tmp*[["c"]]: index outside

I would expect R to return the same error message for a triple nested list as it would for a quadruple nested list

. R 3.4.3 R

+4
1

str(q) , list 'a'. , .

q <- list()
q[["a"]][["b"]] <- 3
q[["a"]][["c"]] <- 4
str(q)
#List of 1
# $ a: Named num [1:2] 3 4
#  ..- attr(*, "names")= chr [1:2] "b" "c"

is.vector(q$a)
#[1] TRUE

, , i.e. 'b', 'c'. list, list

q <- list()
q[["a"]][["b"]][["c"]]<- list(3)
q[["a"]][["b"]][["d"]] <- list(4)

"q" list 1 , "a", list 1 ('b') "3" " 4 '' c '' d ', list 2

str(q)
#List of 1
# $ a:List of 1
#  ..$ b:List of 2
#  .. ..$ c:List of 1
#  .. .. ..$ : num 3
#  .. ..$ d:List of 1
#  .. .. ..$ : num 4

, 'n' list s

q <- list()
q[["a"]][["b"]][["c"]][["d"]] <- list(3)
q[["a"]][["b"]][["c"]][["e"]] <- list(4)

. ,

+4

Source: https://habr.com/ru/post/1694332/


All Articles