Or maybe a better approach is to make test1 and test2 be methods of a class, then it is acceptable if they modify the instance they are running on:x <- proto() # defines a classx$test1 <- function(.) { testvalue <- .$c * .$a * .$b .$a <- 3.5 testvalue}x$test2 <- function(.) { .$a <- 1 .$b <- 2 cat(.$a, '') .$test1() cat(.$a, '')}library(proto)y <- x$proto(c = 3) # an instance of the classy$test2()如果您对使用第三方包 (proto) 不感兴趣,请查看 R 对构建类的支持 (setClass, setRefClass).根据您的规格,我确实相信使用面向对象的设计是正确的方法.If you are not interested in using a third-party package (proto), then look at R's support for building classes (setClass, setRefClass). I do believe using an object-oriented design is the right approach given your specs. 这篇关于在局部变量的嵌套函数中使用“get"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-25 04:33