Tal Galili
2013-Jul-26 21:41 UTC
[R] Is it possible (/reasonable) to write an as.RefClass function for R "list" class?
Hello all. I am interested in creating a mutable "list" object in R. Ideally I would do it through something like this: x <- list(a = list(1:4), b = "miao", c = 4:1) x_RC <- as.RefClass(x) attr(x_RC[[2]], "I am") <- "string" x_RC[[3]] <- x_RC[[3]]+1 x_new <- as.list(x_RC) Is that reasonably possible to create? Or does that make little/no-sense? Thanks. ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
Jeff Newmiller
2013-Jul-26 22:17 UTC
[R] Is it possible (/reasonable) to write an as.RefClass function for R "list" class?
Reference classes are implemented with environment objects, which are mutable. Once you convert to list, the converted object is not mutable, since there is no such thing as a mutable list. So I would say your request is not possible. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Tal Galili <tal.galili at gmail.com> wrote:>Hello all. > > >I am interested in creating a mutable "list" object in R. > >Ideally I would do it through something like this: > >x <- list(a = list(1:4), b = "miao", c = 4:1) >x_RC <- as.RefClass(x) >attr(x_RC[[2]], "I am") <- "string" >x_RC[[3]] <- x_RC[[3]]+1 >x_new <- as.list(x_RC) > >Is that reasonably possible to create? Or does that make >little/no-sense? > >Thanks. > > > > >----------------Contact >Details:------------------------------------------------------- >Contact me: Tal.Galili at gmail.com | >Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) >| >www.r-statistics.com (English) >---------------------------------------------------------------------------------------------- > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.