Yihui Xie
2012-May-22 16:22 UTC
[R] how to remove the 'promise' attribute of an R object (.Random.seed)?
Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] "integer" rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer vector but of type 'promise' typeof(.Random.seed) # [1] "integer" So there must be an "attribute" "promise" somewhere attached to .Random.seed, and I cannot find it. The R function typeof() does not reveal it, but the TYPEOF() function in src/main/RNG.c says it is a 'promise'. My question is, how to make R use the real value of .Random.seed instead of complaining about the promise? Thanks! Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA
luke-tierney at uiowa.edu
2012-May-22 17:49 UTC
[R] how to remove the 'promise' attribute of an R object (.Random.seed)?
On Tue, 22 May 2012, Yihui Xie wrote:> Hi, > > The problem arises when I lazyLoad() the .Random.seed from a > previously saved database. To simplify the process of reproducing the > problem, see the example below: > > ## this assignment may not really make sense, but illustrates the problem > delayedAssign('.Random.seed', 1L) > > typeof(.Random.seed) > # [1] "integer" > > rnorm(1) > # Error in rnorm(1) : > # .Random.seed is not an integer vector but of type 'promise' > > typeof(.Random.seed) > # [1] "integer" > > So there must be an "attribute" "promise" somewhere attached to > .Random.seed, and I cannot find it. The R function typeof() does not > reveal it, but the TYPEOF() function in src/main/RNG.c says it is a > 'promise'. > > My question is, how to make R use the real value of .Random.seed > instead of complaining about the promise? Thanks!Siple answer: Don't creat the promise in the first place, i.e. don't use delayedAssign. What is the real context where this arises? Knowing that may help us decide whether the internals should address this possibility. Best, luke> > Regards, > Yihui > -- > Yihui Xie <xieyihui at gmail.com> > Phone: 515-294-2465 Web: http://yihui.name > Department of Statistics, Iowa State University > 2215 Snedecor Hall, Ames, IA > > ______________________________________________ > 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. >-- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tierney at uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
Duncan Murdoch
2012-May-23 01:08 UTC
[R] how to remove the 'promise' attribute of an R object (.Random.seed)?
On 12-05-22 12:22 PM, Yihui Xie wrote:> Hi, > > The problem arises when I lazyLoad() the .Random.seed from a > previously saved database. To simplify the process of reproducing the > problem, see the example below: > > ## this assignment may not really make sense, but illustrates the problem > delayedAssign('.Random.seed', 1L) > > typeof(.Random.seed) > # [1] "integer" > > rnorm(1) > # Error in rnorm(1) : > # .Random.seed is not an integer vector but of type 'promise' > > typeof(.Random.seed) > # [1] "integer" > > So there must be an "attribute" "promise" somewhere attached to > .Random.seed, and I cannot find it. The R function typeof() does not > reveal it, but the TYPEOF() function in src/main/RNG.c says it is a > 'promise'.You can remove it by a simple assignment: .Random.seed <- .Random.seed will do it. (The reason is that it doesn't copy the object blindly, it evaluates the RHS to get 1L, and it's a regular assignment, so that gets put into the LHS.) Duncan Murdoch> > My question is, how to make R use the real value of .Random.seed > instead of complaining about the promise? Thanks! > > Regards, > Yihui > -- > Yihui Xie<xieyihui at gmail.com> > Phone: 515-294-2465 Web: http://yihui.name > Department of Statistics, Iowa State University > 2215 Snedecor Hall, Ames, IA > > ______________________________________________ > 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.