Dear all, I just noticed that the 0.9 update for FrF2 did not work out for Mac OS due to an error in an example that ran without error on all other platforms. I do not find any reason for this. In the past, umlauts or tab characters have sometimes been an issue, but I didn't find any of these. The function definition is FrF2(nruns = NULL, nfactors = NULL, factor.names = if (!is.null(nfactors)) { if (nfactors <= 50) Letters[1:nfactors] else paste("F", 1:nfactors, sep = "")} else NULL, default.levels = c(-1, 1), generators = NULL, resolution = NULL, estimable = NULL, max.nfree2fis = FALSE, randomize = TRUE, seed = NULL, ...){...} and the simplest call to this function fails: FrF2(8,4) 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.")} Would the Mac (different from all other systems) require FrF2(nruns=8, nfactors=4) ? Or what else could be the issue here ? Thanks for any pointers! Regards, Ulrike -- View this message in context: http://www.nabble.com/Error-in-FrF2-example-on-Mac-OS-tp22675998p22675998.html Sent from the R devel mailing list archive at Nabble.com.
Ulrike Gr?mping wrote:> Dear all, > > I just noticed that the 0.9 update for FrF2 did not work out for Mac OS due > to an error in an example that ran without error on all other platforms. I > do not find any reason for this. In the past, umlauts or tab characters have > sometimes been an issue, but I didn't find any of these. The function > definition is > > FrF2(nruns = NULL, nfactors = NULL, factor.names = if (!is.null(nfactors)) { > if (nfactors <= 50) Letters[1:nfactors] else > paste("F", 1:nfactors, sep = "")} else NULL, > default.levels = c(-1, 1), generators = NULL, resolution = NULL, > estimable = NULL, max.nfree2fis = FALSE, > randomize = TRUE, seed = NULL, ...){...} > > and the simplest call to this function fails: > FrF2(8,4) > 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.") } Uwe> Would the Mac (different from all other systems) require FrF2(nruns=8, > nfactors=4) ? Or what else could be the issue here ? > > Thanks for any pointers! > > Regards, Ulrike
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.
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. Regards, Ulrike -- 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.
On Tue, Mar 24, 2009 at 07:41:31AM -0700, Ulrike Gr?mping wrote:> > 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.Christophe Dutang tested this on Mac with the result > x <- 2^(0:100 + 0) > all(x == floor(x)) [1] TRUE > all(log2(x) == floor(log2(x))) [1] TRUE > x [1] 1.000000e+00 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01 [6] 3.200000e+01 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02 [11] 1.024000e+03 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04 [16] 3.276800e+04 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05 [21] 1.048576e+06 2.097152e+06 4.194304e+06 8.388608e+06 1.677722e+07 [26] 3.355443e+07 6.710886e+07 1.342177e+08 2.684355e+08 5.368709e+08 [31] 1.073742e+09 2.147484e+09 4.294967e+09 8.589935e+09 1.717987e+10 ... Without an analysis of the error directly on Mac, it is hard to guess, what is the problem. What could also be tested is, whether the input nruns is an integer or not. Either strictly, if (nruns != floor(nruns)) stop("nruns not an integer") or with some tolerance nruns0 <- nruns nruns <- round(nruns) if (!isTRUE(all.equal(nruns, nruns0))) stop("nruns not an integer") Petr.