-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.all.tests.r
More file actions
65 lines (64 loc) · 2.44 KB
/
run.all.tests.r
File metadata and controls
65 lines (64 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
rm(list =ls())
if (!file.exists("utilities.R")) stop("utilities.R not in current directory, wrong working directory?")
wd <- getwd()
testdirs0 <- list.dirs(full.names = FALSE, recursive = FALSE)
testdirs0 <- testdirs0[grepl("^[^.]", testdirs0)]
testdirs <- c("HS", "HS_missing", "HS_multi", "Bollen", "Categorical", "MPLUS_ex")
if (!setequal(testdirs0, testdirs)) {
warning("run.all.tests: some subdirectories in sorted list not in filesystem or vice versa")
}
source("utilities.R")
group.environment <- new.env()
assign("i", 0L, group.environment)
cat("STARTING TIME:", format(Sys.time()), "\n")
extesterrors <- file()
for (testdir.i in seq_along(testdirs)) {
setwd(testdirs[testdir.i])
on.exit({
setwd(wd)
})
cat("Processing of tests in", basename(getwd()), "\n")
testfiles <- list.files(pattern = "\\.R$")
sortkeys <- gsub("\\.([0-9])\\.", ".0\\1.", testfiles)
testfiles <- testfiles[order(sortkeys)]
for (test.i in seq_along(testfiles)) {
testfile <- testfiles[test.i]
cat(" handling ", testfile, "\n")
extest <- execute_test(testfile, group.environment)
if (is.character(extest)) {
cat("Comparison skipped: ", extest, "\n")
cat(testfile, " --> ", extest, "\n", file = extesterrors)
if (exists("test.comment")) cat(test.comment, "\n", file = extesterrors)
}
}
setwd(wd)
}
max.i <- get("i", group.environment)
reportcon <- file("report.txt", "wt")
cat("Current lavaan version :",
packageDescription("lavaan", fields = "Version"),
"\n*******************************\n\n",
file = reportcon)
cat("\nTests where comparison with Mplus is skipped: \n---------------------------------------------\n\n", file = reportcon)
cat(paste(readLines(extesterrors), collapse = "\n"), file=reportcon)
close(extesterrors)
cat("\n---------------------------------------------\n\n", file = reportcon)
for (i in seq_len(max.i)) {
ich <- formatC(i, width=4, flag="0")
df1 <- get(paste0("res", ich), group.environment)
res1 <- get(paste0("lav", ich), group.environment)
res2 <- get(paste0("mpl", ich), group.environment)
cat(paste(res1, collapse="\n"), file=reportcon)
cat(paste(res2, collapse="\n"), file=reportcon)
if (i == 1) {
df <- df1
} else {
df <- rbind(df, df1)
}
}
close(reportcon)
rm(group.environment)
saveRDS(df, file = "result.rds")
cat("Logging of tests are in report.txt\n")
cat("Data.frame with overview (variable df) is saved in result.rds\n")
cat("ENDING TIME:", format(Sys.time()), "\n")