deep代入は誤解しがち
http://www.is.titech.ac.jp/~mase/Rtips.html#item53 とか見ると、永続付値=deep代入を.GlobalEnvへの代入と記述している。それだと、.libPaths()のコードは理解できない。
> .libPaths function (new) { if (!missing(new)) { new <- Sys.glob(path.expand(new)) paths <- unique(normalizePath(c(new, .Library.site, .Library), "/")) .lib.loc <<- paths[dir.exists(paths)] } else .lib.loc } <bytecode: 0x0000000005d795e0> <environment: 0x0000000005d778e0> >
help('<<-')を見れば、
The operators <<- and ->> are normally only used in functions, and cause a search to made through parent environments for an existing definition of the variable being assigned. If such a variable is found (and its binding is not locked) then its value is redefined, otherwise assignment takes place in the global environment.
.GlobalEnvに作用するのは、otherwiseのときだけ。.GlobalEnvに辿り着く前に書き換え可能な変数があればそれに作用する。
[追記]
パッケージ所属関数のスコープ(解決) - 檜山正幸のキマイラ飼育記 メモ編 の実験から、パッケージ所属関数でも、グローバルから先のサーチパスを見ている。deep代入のときの変数ルックアップも、この長いサーチパスで行うので、グローバル環境の先にある関数に対してもdeep代入ができる。
長いサーチパス上で当該変数が見つからないときに限り、グローバル環境に“戻って”新しい変数を作る。
[/追記]