I think this is a result of bad design in R (which might be excused because it was inherited from S, I'm not sure). Here's what is going on:
When you run
xxx <<- c(1,2)
R will look for xxx in the parent environments of the current environment (which is shown by printing the result of environment(), i.e. <environment: R_GlobalEnv>). This search fails, because there's no xxx higher up in the environment tree. At this point, a good design would signal an error and you wouldn't try that again.
However, R doesn't signal an error, it defaults to making the assignment in globalenv(). This leads to tons of confusion, e.g. to people thinking <<- means "global assignment", when really it means "assignment to an ancestor environment or maybe global". It would be better if it was just "assignment to an ancestor environment".
Your second assignment is more complicated, because it assigns to a subset of xxx. If you had used the regular assignment operator
xxx[1:2] <- c(11, 22)
R would go through several steps. As the Language manual explains, these are equivalent to
`*tmp*` <- xxx
xxx <- "[<-"(`*tmp*`, 1:2, value=c(11, 22))
rm(`*tmp*`)
The manual also explains what happens when you do both, as in your
xxx[1:2] <<- c(11, 22)
though I think there are typos. Correcting those, this is equivalent to
`*tmp*` <- get("xxx", envir=parent.env(), inherits=TRUE)
`*tmp*`[1:2] <- c(11, 22)
xxx <<- `*tmp*`
rm(`*tmp*`)
and here the first line fails, because xxx is not in the parent environment. This is a good thing. We should have had a failure in
xxx <<- c(1,2)
too, but we don't because of the bad design.
<<-in the global environment.xxxwas created in and in which the assignment is taking place. The purpose of this operator is to assign in the parent environment, which certainly isn't happening in the question as it's currently written.?"<<-"help page: The operators ‘<<-’ and ‘->>’ are normally only used in functions.<<-function is used to assign a value to a vector in the next “higher” environment, but it appears you are executing it in the base environment for which there is nothing “higher”.