Re: [Rd] Is aggregate() function changing?
Thank your Dr. Duncan Murdoch: Yes, you are right! I look for a "mean" variable and there it was!!! It seems to work on the non-patched 2.8.1 version because I start a new session on a diferent directory, and with the patched 2.8.1 I use an already created .Rdata where a "mean" variable exist with a 0 value. Thank you very much for your help. Sorry for this silly questions. Kenneth El mar, 24-03-2009 a las 07:07 -0400, Duncan Murdoch escribió: > On 24/03/2009 12:44 AM, Kenneth Roy Cabrera Torres wrote: > > Hi R developers and debian users: > > > > Finally I found how to work with aggregate() function > > on the last patched version fo R. > > > > I you use this command it fails: > > > > aggregate(state.x77, list(Region = state.region), mean) > > > > But if you modify it in this way, it works!: > > > > aggregate(state.x77, list(Region = state.region), function(x) mean(x) ) > > > > Is it necesary to change the example? > > > > What is changing in aggregate() function? > > I get identical results from those, but if I had a local variable (not a > function) named "mean", the first one would not work: > > > mean <- 2 > > aggregate(state.x77, list(Region = state.region), mean) > Error in FUN(X[[1L]], ...) : element 1 is empty; > the part of the args list of 'is.list' being evaluated was: > (INDEX) > > I suspect that is what is going wrong for you. > > Duncan Murdoch > > > > > > Thank you for your attention. > > > > Kenneth. > >> sessionInfo() > > > > R version 2.8.1 Patched (2009-03-18 r48193) > > x86_64-unknown-linux-gnu > > > > locale: > > LC_CTYPE=es_CO.UTF-8;LC_NUMERIC=C;LC_TIME=es_CO.UTF-8;LC_COLLATE=es_CO.UTF-8;LC_MONETARY=C;LC_MESSAGES=es_CO.UTF-8;LC_PAPER=es_CO.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=es_CO.UTF-8;LC_IDENTIFICATION=C > > > > attached base packages: > > [1] stats graphics grDevices utils datasets methods base > > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] More Embedding REngine in Cocoa
DAvid, On Mar 25, 2009, at 2:44 , David Zwerdling wrote: Hello once again, After locating the standalone REngine object set, I am having difficulty integrating them into the XCode project I intend to use them in. Suppose one started with the REngine standalone source and a blank XCode file, what special modifications need to be made to allow the source files to see inside R.framework? Importing the framework into the project, setting the header and framework search paths hasn't done anything for me yet. You only need to set the header path to include Headers and PrivateHeaders of the R.framework - everything else follows automatically from adding the R.framework to the project. From R.xcodeproj: HEADER_SEARCH_PATHS = ( /Library/Frameworks/R.framework/Headers, /Library/Frameworks/R.framework/PrivateHeaders, ); That's all. The files are complaining about the R.h file not existing. Using the R.app as a reference, I was unable to find specifically how it adds the R/ directory visibility to the application headers at link or compile time. See above. I was able to compile and run the test file inside the REngine standalone. However, I don't know how to initiate my application in XCode using the R CMD command. What impacts will this have to the existing program? Essentially R CMD sets up the environment for R automatically. If you have a stand-alone application and you cannot (or don't want to) use R CMD then have a look at the R.app GUI - it creates the environment itself in RController.m l.306-373 (current SVN r5376). The following code (l.375-420) then sets up the locale - it may be a bit more complicated than what you need, but you just have to ensure you're running in a UTF-8 locale. [Note: Finally, I was also unable to find any sort of implementation of this in RGui. Is this even necessary from XCode? See above. Cheers, Simon I hope this is enough detail. Thanks in advance. David Zwerdling zwerd...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Error in FrF2 example on Mac OS
On Mar 24, 2009, at 10:41 , Ulrike Grömping wrote: Petr Savicky wrote: On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote: gives the custom error message "nruns must be a power of 2.", which is generated in the first check within function FrF2: if (!is.null(nruns)){ k <- floor(log2(nruns)) if (!2^k==nruns) stop("nruns must be a power of 2.")} Probably a rounding issue on different platforms? I guess the test should be something like: if (!is.null(nruns)){ if(!isTRUE(all.equal(log2(nruns) %% 1, 0))) stop("nruns must be a power of 2.") } Probably, k is needed also later. Assumig that 2^k works correctly, the following could be sufficient if (!is.null(nruns)){ k <- round(log2(nruns)) if (!2^k==nruns) stop("nruns must be a power of 2.")} In order to test the assumption, one can use x <- 2^(0:100 + 0) # use double exponent to be sure all(x == floor(x)) Powers of two are represented exactly, since they have only one significant bit. Petr. Yes, round instead of floor should also do the job, if rounding is the issue. But then, with powers of 2 indeed being represented exactly (I would expect even on Macs), maybe rounding is not the issue? I have no possibility to check this, since I do not have access to a Mac with R installed. On my windows machine, all(log2(x)==floor(log2(x))) with x as defined above yields TRUE. What you're missing is that you cannot rely on log2 to give you an integer. The test above bears no relevance to your problem - this is not about representing 2^x - this is about log2 which you cannot expect to satisfy log2(2^b) == b numerically since it could as well be computed log(x)/log(2) which is not exactly representable. Use round and all is well :). > which(floor(log2(2^x))!=x) [1] 4 7 8 13 14 15 25 27 29 49 53 57 64 97 > which(round(log2(2^x))!=x) integer(0) Cheers, Simon View this message in context: http://www.nabble.com/Error-in-FrF2-example-on-Mac-OS-tp22675998p22681913.html Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] no internal function "int.unzip" in R 2.9 on Windows
Dear list, Using R 2.9, I have the following error on Windows when I try using .Internal(int.unzip(...)): > .Internal(int.unzip("test.zip",NULL, ".")) Error in .Internal(int.unzip("test.zip", NULL, ".")) : no internal function "int.unzip" The same error also happens with R 2.10 but not on R 2.8. And it does not happen with R 2.9 on Mac or Unix. I have googled the error message but cannot find much. Does anyone know if the way R calls unzip functions on Windows has changed and if this is permanent? I am sorry if I miss something obvious, but any suggestions on how I can fix the problem? I want to keep using int.unzip and not the utils function unzip because I use its output afterwards in my script. Best wishes, Audrey __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] no internal function "int.unzip" in R 2.9 on Windows
On 3/25/2009 11:42 AM, aud...@ebi.ac.uk wrote: Dear list, Using R 2.9, I have the following error on Windows when I try using .Internal(int.unzip(...)): .Internal(int.unzip("test.zip",NULL, ".")) Error in .Internal(int.unzip("test.zip", NULL, ".")) : no internal function "int.unzip" The same error also happens with R 2.10 but not on R 2.8. And it does not happen with R 2.9 on Mac or Unix. I have googled the error message but cannot find much. Does anyone know if the way R calls unzip functions on Windows has changed and if this is permanent? I am sorry if I miss something obvious, but any suggestions on how I can fix the problem? I want to keep using int.unzip and not the utils function unzip because I use its output afterwards in my script. Generally internal things that aren't documented as part of the API are subject to change without notice. Rather than relying on the way certain functions happen to work in certain versions, if you find that one of the documented functions doesn't do what you want, you should point out the problem with it and submit a patch. You can see how the unzip function in the utils package works by looking at the source, or just printing it in the console. It doesn't refer to int.unzip, but I wouldn't count on its current behaviour being "permanent": it's undocumented internal implementation, which you use at your own risk. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] no internal function "int.unzip" in R 2.9 on Windows
aud...@ebi.ac.uk wrote: Dear list, Using R 2.9, I have the following error on Windows when I try using .Internal(int.unzip(...)): .Internal(int.unzip("test.zip",NULL, ".")) Error in .Internal(int.unzip("test.zip", NULL, ".")) : no internal function "int.unzip" The same error also happens with R 2.10 but not on R 2.8. And it does not happen with R 2.9 on Mac or Unix. I have googled the error message but cannot find much. Does anyone know if the way R calls unzip functions on Windows has changed and if this is permanent? Indeed, there was a change and int.unzip was never documented as part of the API. It was intended to work "Internal"ly. You can use the unzip() function in package utils now, see the NEWS file. Best, Uwe Ligges I am sorry if I miss something obvious, but any suggestions on how I can fix the problem? I want to keep using int.unzip and not the utils function unzip because I use its output afterwards in my script. Best wishes, Audrey __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] no internal function "int.unzip" in R 2.9 on Windows
Dear Duncan and Uwe, Thank you for your prompt answers. I will have a look at the unzip function and try to modify it to make it producing the output I want. Cheers, Audrey > On 3/25/2009 11:42 AM, aud...@ebi.ac.uk wrote: >> Dear list, >> >> Using R 2.9, I have the following error on Windows when I try using >> .Internal(int.unzip(...)): >> >>> .Internal(int.unzip("test.zip",NULL, ".")) >> Error in .Internal(int.unzip("test.zip", NULL, ".")) : >> no internal function "int.unzip" >> >> The same error also happens with R 2.10 but not on R 2.8. And it does >> not >> happen with R 2.9 on Mac or Unix. >> I have googled the error message but cannot find much. >> >> Does anyone know if the way R calls unzip functions on Windows has >> changed >> and if this is permanent? >> I am sorry if I miss something obvious, but any suggestions on how I can >> fix the problem? >> I want to keep using int.unzip and not the utils function unzip because >> I >> use its output afterwards in my script. > > Generally internal things that aren't documented as part of the API are > subject to change without notice. Rather than relying on the way > certain functions happen to work in certain versions, if you find that > one of the documented functions doesn't do what you want, you should > point out the problem with it and submit a patch. > > You can see how the unzip function in the utils package works by looking > at the source, or just printing it in the console. It doesn't refer to > int.unzip, but I wouldn't count on its current behaviour being > "permanent": it's undocumented internal implementation, which you use > at your own risk. > > Duncan Murdoch > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] get_all_vars fails with matrices (PR#13624)
Hi, According to the help file for model.frame/get_all_vars, the following should produce the same output from both functions, but it doesn't... > dat <- list(X=matrix(1:15,5,3),z=26:30) > model.frame(~z+X,dat) z X.1 X.2 X.3 1 26 1 6 11 2 27 2 7 12 3 28 3 8 13 4 29 4 9 14 5 30 5 10 15 > get_all_vars(~z+X,dat) [1] zX <0 rows> (or 0-length row.names) > -- the equivalent works ok if there are no matrices involved. I'm using R version 2.9.0 alpha (2009-03-24 r48212) (Suse linux 10 and 11, 64 bit intel). I found the problem while trying to fix a problem in an mgcv plotting routine. best, Simon -- > Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Listing of LAPACK error codes
Professor Ripley commented on LAPACK error codes: https://stat.ethz.ch/pipermail/r-help/2007-March/127702.html and says "Internal LAPACK errors are usually problems with arithmetic accuracy, and as such are compiler- and CPU-specific." Is there a listing for the error codes from Lapack routine 'dsyevr'? Especially I am interested about the meaning and handling of error codes 1 and 2. In Lapack.c I only see the reference to the variable info in certain Fortran code: F77_CALL(dsyevr)(jobv, range, uplo, &n, rx, &n, &vl, &vu, &il, &iu, &abstol, &m, rvalues, rz, &n, isuppz, &tmp, &lwork, &itmp, &liwork, &info); if (info != 0) error(_("error code %d from Lapack routine '%s'"), info, "dsyevr"); lwork = (int) tmp; liwork = itmp; work = (double *) R_alloc(lwork, sizeof(double)); iwork = (int *) R_alloc(liwork, sizeof(int)); F77_CALL(dsyevr)(jobv, range, uplo, &n, rx, &n, &vl, &vu, &il, &iu, &abstol, &m, rvalues, rz, &n, isuppz, work, &lwork, iwork, &liwork, &info); if (info != 0) error(_("error code %d from Lapack routine '%s'"), info, "dsyevr"); [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] linking environments
Dear R-helpers, I try to use nested R-functions as follows: help1 = function(){ x = 1 help2() } with help2 = function(){ if (x == 1) cat("Hello world x = 1") } If I compile these functions and run help1() an error message occurs Fehler in help2() : objekt "x" nicht gefunden in english "error in help2(): object "x" not found" If I change help1 to help1 = function(){ x <<- 1 help2() } so that "x" is now defined at the global environment it works fine. But the problem is, now "x" is defined also outside of help1 and this is not desired ! Is there any usable solution for this problem? But, the original problem is to assign new values for "x" in help1 inside help2 ! Thanks in advance Jörg Betzin --- Deutsches Zentrum für Altersfragen Manfred-von-Richthofen-Str. 2 12101 Berlin Tel. (030) 260740-20 E-Mail: joerg.bet...@dza.de URL: http://www.dza.de --- [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] linking environments
On 3/25/2009 11:47 AM, Joerg Betzin wrote: Dear R-helpers, I try to use nested R-functions as follows: You didn't use nested functions. They would look like this: help1 <- function(){ help2 <- function(){ if (x == 1) cat("Hello world x = 1") } x <- 1 help2() } Because help2 is now nested within help1, it can see all the local variables in help1, so things work with it done this way. There are tricks to define help2 outside of help1 but allow it to see the variables within there, but I'd keep it simple and avoid them. Duncan Murdoch help1 = function(){ x = 1 help2() } with help2 = function(){ if (x == 1) cat("Hello world x = 1") } If I compile these functions and run help1() an error message occurs Fehler in help2() : objekt "x" nicht gefunden in english "error in help2(): object "x" not found" If I change help1 to help1 = function(){ x <<- 1 help2() } so that "x" is now defined at the global environment it works fine. But the problem is, now "x" is defined also outside of help1 and this is not desired ! Is there any usable solution for this problem? But, the original problem is to assign new values for "x" in help1 inside help2 ! Thanks in advance Jörg Betzin --- Deutsches Zentrum für Altersfragen Manfred-von-Richthofen-Str. 2 12101 Berlin Tel. (030) 260740-20 E-Mail: joerg.bet...@dza.de URL: http://www.dza.de --- [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] linking environments
> > -Original Message- > From: r-devel-boun...@r-project.org on behalf of Joerg Betzin > Sent: Wed 3/25/2009 8:47 AM > To: r-devel@r-project.org > Subject: [Rd] linking environments > > Dear R-helpers, > > I try to use nested R-functions as follows: Looks like a question for R-help, not R-devel. It's better to post such questions to the r-h...@r-project.org mailing list. > > help1 = function(){ > x = 1 > help2() > } > > with > > help2 = function(){ > if (x == 1) > cat("Hello world x = 1") > } > > If I compile these functions and run help1() > an error message occurs > Fehler in help2() : objekt "x" nicht gefunden > > in english "error in help2(): object "x" not found" > Why not pass the value of x from help1 to help2? help1 <- function(){ x <- 1 help2(x) } help2 <- function(x){ if (x == 1) cat("Hello world x = 1") } > help1 <- function(){ + x <- 1 + help2(x) + } > > > > help2 <- function(x){ + if (x == 1) + cat("Hello world x = 1") + } > > > > help1() Hello world x = 1> (No compiling is involved.) > If I change help1 to > > help1 = function(){ > x <<- 1 > help2() > } > > so that "x" is now defined at the global environment it works fine. > But the problem is, now "x" is defined also outside of help1 and this is > not desired ! > > Is there any usable solution for this problem? > But, the original problem is to assign new values for "x" in help1 inside > help2 ! Is this a homework problem? Some reading of ?environment will help answer this. > > Thanks in advance > > Jörg Betzin > --- > Deutsches Zentrum für Altersfragen > Manfred-von-Richthofen-Str. 2 > 12101 Berlin > Tel. (030) 260740-20 > E-Mail: joerg.bet...@dza.de > URL: http://www.dza.de > --- > > [[alternative HTML version deleted]] > Steven McKinney, Ph.D. Statistician Molecular Oncology and Breast Cancer Program British Columbia Cancer Research Centre email: smckinney +at+ bccrc +dot+ ca tel: 604-675-8000 x7561 BCCRC Molecular Oncology 675 West 10th Ave, Floor 4 Vancouver B.C. V5Z 1L3 Canada __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] get_all_vars fails with matrices (PR#13624)
s.w...@bath.ac.uk wrote: Hi, According to the help file for model.frame/get_all_vars, the following should produce the same output from both functions, but it doesn't... dat <- list(X=matrix(1:15,5,3),z=26:30) model.frame(~z+X,dat) z X.1 X.2 X.3 1 26 1 6 11 2 27 2 7 12 3 28 3 8 13 4 29 4 9 14 5 30 5 10 15 get_all_vars(~z+X,dat) [1] zX <0 rows> (or 0-length row.names) -- the equivalent works ok if there are no matrices involved. I'm using R version 2.9.0 alpha (2009-03-24 r48212) (Suse linux 10 and 11, 64 bit intel). I found the problem while trying to fix a problem in an mgcv plotting routine. best, Simon This works, though: > dat <- data.frame(X=I(matrix(1:15,5,3)),z=26:30) > get_all_vars(~z+X,dat) z X.1 X.2 X.3 1 26 1 6 11 2 27 2 7 12 3 28 3 8 13 4 29 4 9 14 5 30 5 10 15 but there is something special with lists: > dat <- as.data.frame(list(X=I(matrix(1:15,5,3)),z=26:30)) > get_all_vars(~z+X,dat) z X.1 X.2 X.3 1 26 1 6 11 2 27 2 7 12 3 28 3 8 13 4 29 4 9 14 5 30 5 10 15 > dat <- data.frame(list(X=I(matrix(1:15,5,3)),z=26:30)) > get_all_vars(~z+X,dat) z X.1 X.2 X.3 1 26 1 6 11 2 27 2 7 12 3 28 3 8 13 4 29 4 9 14 5 30 5 10 15 > dat <- list(X=I(matrix(1:15,5,3)),z=26:30) > get_all_vars(~z+X,dat) [1] z X <0 rows> (or 0-length row.names) > -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Listing of LAPACK error codes
And Orlando Döhring writes: > Is there a listing for the error codes from Lapack routine 'dsyevr'? The HTML-ized LAPACK functions are at http://www.netlib.org/lapack/explore-html/ although they may lag behind releases a little bit. The page for dsyevr.f is: http://www.netlib.org/lapack/explore-html/dsyevr.f.html And the LAPACK mailing list is at lap...@cs.utk.edu, although as with all such projects, responses may be a *long* time in coming. > Especially I am interested about the meaning and handling of error codes 1 > and 2. The high-level drivers like DSYEVR dispatch to different internal routines depending on what was requested. That makes documenting the error codes a little painful... For some of the routines involved, INFO.eq.1 or 2 implies 1 or 2 entries didn't converge, either when reducing a tridiagonal to diagonal, in bisection, or in inverse iteration. For another, but only if you're requesting the ilo-th through ihi-th eigenvalues, 2 would imply non-monotonic arithmetic, and I would be *very* surprised. So likely something somewhere didn't converge. Picking parameters that *always* converge for eigenvalues is an open problem. Have you tried this on different platforms, or with different BLAS? Can you release the data that causes the problem? Jason __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Listing of LAPACK error codes
On Wed, 25 Mar 2009, Orlando Döhring wrote: Professor Ripley commented on LAPACK error codes: https://stat.ethz.ch/pipermail/r-help/2007-March/127702.html and says "Internal LAPACK errors are usually problems with arithmetic accuracy, and as such are compiler- and CPU-specific." Is there a listing for the error codes from Lapack routine 'dsyevr'? Especially I am interested about the meaning and handling of error codes 1 and 2. In Lapack.c I only see the reference to the variable info in certain Fortran code: I read the LAPACK sources: I know of no other documentation. (You seem to have missed the sources, which are part of R.) F77_CALL(dsyevr)(jobv, range, uplo, &n, rx, &n, &vl, &vu, &il, &iu, &abstol, &m, rvalues, rz, &n, isuppz, &tmp, &lwork, &itmp, &liwork, &info); if (info != 0) error(_("error code %d from Lapack routine '%s'"), info, "dsyevr"); lwork = (int) tmp; liwork = itmp; work = (double *) R_alloc(lwork, sizeof(double)); iwork = (int *) R_alloc(liwork, sizeof(int)); F77_CALL(dsyevr)(jobv, range, uplo, &n, rx, &n, &vl, &vu, &il, &iu, &abstol, &m, rvalues, rz, &n, isuppz, work, &lwork, iwork, &liwork, &info); if (info != 0) error(_("error code %d from Lapack routine '%s'"), info, "dsyevr"); [[alternative HTML version deleted]] Overdue to read the posting guide -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Error in FrF2 example on Mac OS
-- Original Message --- From: Simon Urbanek To: Ulrike Grömping Cc: r-devel@r-project.org Sent: Wed, 25 Mar 2009 10:32:59 -0400 Subject: Re: [Rd] Error in FrF2 example on Mac OS > On Mar 24, 2009, at 10:41 , Ulrike Grömping wrote: > > > > > > > Petr Savicky wrote: > >> > >> On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote: > gives the custom error message "nruns must be a power of 2.", > which is > generated in the first check within function FrF2: > > if (!is.null(nruns)){ > k <- floor(log2(nruns)) > if (!2^k==nruns) stop("nruns must be a power of 2.")} > >>> > >>> > >>> Probably a rounding issue on different platforms? > >>> I guess the test should be something like: > >>> > >>> if (!is.null(nruns)){ > >>> if(!isTRUE(all.equal(log2(nruns) %% 1, 0))) > >>> stop("nruns must be a power of 2.") > >>> } > >> > >> Probably, k is needed also later. Assumig that 2^k works correctly, > >> the following could be sufficient > >> > >> if (!is.null(nruns)){ > >> k <- round(log2(nruns)) > >> if (!2^k==nruns) stop("nruns must be a power of 2.")} > >> > >> In order to test the assumption, one can use > >> > >> x <- 2^(0:100 + 0) # use double exponent to be sure > >> all(x == floor(x)) > >> > >> Powers of two are represented exactly, since they have only one > >> significant bit. > >> > >> Petr. > >> > > > > Yes, round instead of floor should also do the job, if rounding is the > > issue. But then, with powers of 2 indeed being represented exactly > > (I would > > expect even on Macs), maybe rounding is not the issue? I have no > > possibility > > to check this, since I do not have access to a Mac with R installed. > > On my > > windows machine, > > all(log2(x)==floor(log2(x))) > > with x as defined above yields TRUE. > > > > What you're missing is that you cannot rely on log2 to give you an > integer. The test above bears no relevance to your problem - this is > not about representing 2^x - this is about log2 which you cannot > expect to satisfy log2(2^b) == b numerically since it could as well be > computed log(x)/log(2) which is not exactly representable. Use round > and all is well :). > > > which(floor(log2(2^x))!=x) > [1] 4 7 8 13 14 15 25 27 29 49 53 57 64 97 > > which(round(log2(2^x))!=x) > integer(0) > > Cheers, > Simon > Yes, round did indeed solve the problem, it just surprises me that the Mac is so different from the other (binary) animals. Regards, Ulrike __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel