-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathundergrad.R
More file actions
81 lines (81 loc) · 2.58 KB
/
undergrad.R
File metadata and controls
81 lines (81 loc) · 2.58 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
undergrad <- function (control = "control.txt", stem = T, strip.tags = T,
ignore.case = T, table.file = "tablefile.txt", threshold = 0.01,
pyexe = NULL, sep = NULL, printit = TRUE, fullfreq = FALSE,
python3 = FALSE, alphanumeric.only = TRUE, textincontrol = FALSE,
remove.regex = NULL)
{
os.type <- .Platform$OS.type
if (is.null(pyexe))
pyexe <- "python"
if (python3 == FALSE) {
call <- paste(system.file("makerfile", package = "ReadMe"), sep = "")
}
else {
call <- paste(system.file("makerfile3-0.py", package = "ReadMe"), sep = "")
}
if (!stem)
call <- paste(call, "--no-stem")
if (!strip.tags)
call <- paste(call, "--tags")
if (!ignore.case)
call <- paste(call, "--case-sensitive")
if (!printit)
call <- paste(call, "--silent")
if (alphanumeric.only)
call <- paste(call, "--alphanumeric-only")
if (textincontrol)
call <- paste(call, "--in-control-file")
if (is.data.frame(control)) {
write.table(control, "readmetmpctrl.txt", row.names = FALSE,
quote = FALSE)
control <- "readmetmpctrl.txt"
}
if (!is.null(sep)) {
call <- paste(call, " --separator \",\"", sep = "")
}
if (!is.null(remove.regex)) {
call <- paste(call, " --remove-regex ", "'", remove.regex,
"'", sep = "")
}
call <- paste(call, "--control-file", paste(control, sep = ""))
call <- paste(call, "--table-file", paste(table.file, sep = ""))
call <- paste(call, "--threshold", threshold)
print(paste(pyexe, call))
sysres <- system(paste(pyexe, call))
if (sysres == -1) {
if (os.type == "unix")
stop("Python pyexe must be installed and on system path.")
pyexe <- NULL
for (i in 10:50) {
pyexe <- paste("/python", i, "/python.exe", sep = "")
if (file.exists(pyexe)) {
warning(paste("Python not on path. Using", pyexe))
break
}
}
if (is.null(pyexe)) {
stop("Python pyexe must be installed and on system path.")
}
sysres <- system(paste(pyexe, call))
}
if (sysres != 0) {
stop("Python module failed. Aborting undergrad.")
}
tab <- read.csv(table.file)
ret <- list()
ret$trainingset <- tab[tab$TRAININGSET == 1, ]
ret$testset <- tab[tab$TRAININGSET == 0, ]
cnames <- colnames(tab)
ncols <- length(cnames)
formula <- paste(cnames[4], "+...+", cnames[ncols], "~TRUTH",
sep = "")
formula <- as.formula(formula)
ret$formula <- formula
ret$features <- 15
ret$n.subset <- 300
ret$prob.wt <- 1
ret$boot.se <- FALSE
ret$nboot = 300
ret$printit = printit
return(ret)
}