Skip to content

Commit 5589189

Browse files
author
maechler
committed
amend r85694: only set LC_COLLATE = C
git-svn-id: https://svn.r-project.org/R/trunk@85705 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent c786526 commit 5589189

File tree

1 file changed

+13
-58
lines changed

1 file changed

+13
-58
lines changed

src/library/stats/tests/glm-etc.R

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ set.seed(7)
178178
mydatC <- data.frame(x = sort(rnorm(49)), ch = c(LETTERS[1:3], letters[1:4]))
179179
mydatC$y <- with(mydatC, 20*x + 10 - (ch2num(ch) - 68) + rnorm(x))
180180
str(mydatC)
181-
if(dev.interactive()) ## visualize:
181+
if(dev.interactive(TRUE)) ## visualize:
182182
plot(y ~ x, data=mydatC, col = factor(ch))
183183

184184
Sys.setlocale("LC_COLLATE", "C")
@@ -192,94 +192,49 @@ str(mydatF)
192192
## [1] "Component “call”: target, current do not match when deparsed"
193193
stopifnot(length(ae.cf) == 1L, grepl("^Component .call.:", ae.cf))
194194

195-
Sys.setlocale("LC_COLLATE", "de_CH.UTF-8")
196-
## but still, summary.lm(fmC) does *not* depend on the locale:
197-
stopifnot(identical(summary(fmCc), sfmCc))
198-
199-
## data version with de_CH locale --> different level order
200-
mydatF8 <- mydatC; mydatF8$ch <- factor(mydatC$ch)
201-
str(mydatF8)
202-
## $ ch: Factor w/ 7 levels "a","A","b","B",..: 2 4 6 1 3 5 7 2 4 6 ...
203-
204-
## "charactor not factor" data -- now different lm() coeff:
205-
(sfmCH8c <- summary(fmCH8c <- lm(y ~ ., data=mydatC)))
206-
## lm() with *factor* data is the "same"
207-
sfmCH8f <- summary(fmCH8f <- lm(y ~ ., data=mydatF))
208-
## ... very similar to the fmCc and fmCf summaries:
209-
stopifnot(all.equal(sfmCH8f, sfmCf))
210-
(ae8f <- all.equal(sfmCH8f, sfmCc)) # only "call" differs
211-
stopifnot(length(ae8f) == 1L, grepl("^Component .call.:", ae8f))
212-
213-
sfmCH8f8 <- summary(fmCH8f8 <- lm(y ~ ., data=mydatF8))
214-
## as the fmCH8c above :
215-
(aeC8 <- all.equal(sfmCH8f8, sfmCH8c)) # only "call" ..
216-
stopifnot(length(aeC8) == 1L, grepl("^Component .call.:", aeC8))
217-
218195
coef(fmCc)
219196
## (Intercept) x chB chC cha chb chc chd
220197
## 12.7781626 19.8494272 -0.8240301 -1.3309157 -31.7032317 -32.8819084 -33.3519985 -34.6249161
221198
(coef(fmCf) -> cf.f) # the same
222-
coef(fmCH8f) -> cf.8 # same again : factor() was called during "C" locale!
223199
stopifnot(exprs = {
224200
identical(coef(fmCc), cf.f)
225-
identical(cf.f, cf.8)
226201
})
227202

228-
coef(fmCH8c) ## different, indeed
229-
## (Intercept) x chA chb chB chc chC chd
230-
## -18.925069 19.849427 31.703232 -1.178677 30.879202 -1.648767 30.372316 -2.921684
231-
232-
(dummy.coef(fmCc) -> df.Cc)
203+
(dummy.coef(fmCc) -> dc.Cc) ##-- was all wrong in R <= 4.3.2
233204
## (Intercept): 12.77816
234205
## x: 19.84943
235206
## ch: A B C a b c d
236207
## 0.0000000 -0.8240301 -1.3309157 -31.7032317 -32.8819084 -33.3519985 -34.6249161
237208
dummy.coef(fmCf) -> dc.Cf # the same
238-
dummy.coef(fmCH8f) -> dc.8f # also the same, indeed, typically even identical (not testing):
239-
identical(dc.Cf, dc.8f) # TRUE
240209
all.equal15 <- function(x,y, ...) all.equal(x,y, tolerance = 1e-15, ...)
241210
stopifnot(exprs = {
242-
all.equal15(dc.Cf, dc.Cf)
243-
all.equal15(dc.Cf, dc.8f)
244-
## coef() <--> dummy.coef() :
211+
all.equal15(dc.Cc, dc.Cf) # *not* in R <= 4.3.2
212+
## coef() <--> dummy.coef() {was always true}
245213
length(dcCf <- unlist(dc.Cf)) == 1 + length(cf.f)
246214
is.character(names(dcCf) <- sub("[.]", "", names(dcCf)))
247215
all.equal15(dcCf[i2 <- 1:2], cf.f[i2], check.attributes = FALSE)
248216
all.equal15(dcCf[-i2], c(chA = 0, cf.f[-i2]))
249217
})
250218

251-
dummy.coef(fmCH8c) # *is* different
252-
## (Intercept): -18.92507
253-
## x: 19.84943
254-
## ch: a A b B c C d
255-
## 0.000000 31.703232 -1.178677 30.879202 -1.648767 30.372316 -2.921684
256-
257219
##============= + 2 way interactions ============================================
258-
(sfm2c <- summary(fm2c <- lm(y ~ .^2, data=mydatC)))
259-
sfm2f8 <- summary(fm2f8<- lm(y ~ .^2, data=mydatF8))
260-
(dc2c <- dummy.coef(fm2c))
261-
iC <- match("call", names(sfm2c))
262-
all.equal(sfm2c, sfm2f8)
220+
fm2c <- lm(y ~ .^2, data=mydatC)
221+
cf2c <- coef(fm2c)
222+
(dc2c <- dummy.coef(fm2c)) # *wrong* in R <= 4.3.2
263223
stopifnot(exprs = {
264-
all.equal15(sfm2c [-iC],
265-
sfm2f8[-iC])
266-
all.equal15(cf2c <- coef(fm2c),
267-
coef(fm2f8))
268-
all.equal15(dc2c, dummy.coef(fm2f8))
269-
length(dc2c <- unlist(dc2c)) == 2 + length(cf2c)
270-
224+
length(dc2c <- unlist(dc2c)) == 2 + length(cf2c) # was false
271225
all.equal15(dc2c[1:2], cf2c[1:2], check.attributes = FALSE)
272226
is.character(names(dc2c) <- sub("[.]", "", names(dc2c)))
273227
all.equal15(dc2c[-(1:2)][1:7],
274-
c(cha = 0, cf2c[-(1:2)][1:6]))
228+
c(chA = 0, cf2c[-(1:2)][1:6]))
275229
all.equal15(tail(dc2c, 7),
276-
c(`x:cha` = 0, tail(cf2c, 6)))
230+
c(`x:chA` = 0, tail(cf2c, 6)))
277231
})
278232

279-
(sfm2f <- summary(fm2f <- lm(y ~ .^2, data=mydatF))) # different
233+
fm2f <- lm(y ~ .^2, data=mydatF) # was always correct
280234
(dc2f <- dummy.coef(fm2f))
281-
cf2f <- coef(fm2f)
235+
cf2f <- coef(fm2f)
282236
stopifnot(exprs = {
237+
## were all TRUE before
283238
length(dc2f <- unlist(dc2f)) == 2 + length(cf2f)
284239
all.equal(dc2f[1:2], cf2f[1:2], check.attributes = FALSE)
285240
is.character(names(dc2f) <- sub("[.]", "", names(dc2f)))

0 commit comments

Comments
 (0)