R: copy/move one environment to another

前端 未结 7 2041
-上瘾入骨i
-上瘾入骨i 2020-12-14 02:01

I would like to ask if it is possible to copy/move all the objects of one environment to another, at once. For example:

f1 <- function() {
    print(v1)
          


        
7条回答
  •  忘掉有多难
    2020-12-14 02:40

    I use this function in my package to copy objects:

    copyEnv <- function(from, to, names=ls(from, all.names=TRUE)) {
      mapply(assign, names, mget(names, from), list(to), 
             SIMPLIFY = FALSE, USE.NAMES = FALSE)
      invisible(NULL)
    }
    

提交回复
热议问题