-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path.init.R
70 lines (55 loc) · 1.94 KB
/
.init.R
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
# .init.R
# Functions to initialize this session
# Boris Steipe
# ==============================================================================
cat("Initializing ...\n")
# Source local functions
cat(" sourcing local functions from \"./R\" directory ...\n")
for (script in list.files(path = "./R",
pattern = "\\.R$",
full.names = TRUE)) {
source(script)
cat(sprintf(" ... %s\n", script))
}
cat("\n")
# Functions for making local, editable copies of scripts
checkFileExists <- function(FN) {
if (! file.exists(FN)) {
stop(sprintf("PANIC: expected file \"%s\" not found. \ %s ",
FN,
"Aborting initialization. Contact your instructor.\n\n"))
}
}
writeMyCopy <- function(FN, prefix = "my", outFile) {
# Create a local copy of file FN if the copy doesn't exist yet.
# Side effect: write it to <prefix><FN>, or to outFile, if outFile
# is specified.
if (missing(outFile)) {
outFile <- sprintf("%s%s", prefix, FN)
i <- nchar(prefix) + 1
substr(outFile, i, i) <- toupper(substr(outFile, i, i))
}
checkFileExists(FN)
if (! file.exists(outFile)) {
cat(sprintf(" creating local script file: \"%s\" ... ", outFile))
txt <- readLines(FN)
txt[1] <- sprintf("# %s", outFile)
txt[5] <- sprintf("# | %s%s |",
"Edit this file with your notes,",
" experiments, and comments.")
writeLines(txt, outFile)
cat(" oK.\n")
}
}
# Create a local copy of all core .R modules if those copies don't exist yet.
writeMyCopy("journal.md")
writeMyCopy("sequenceAnalysis.R")
writeMyCopy("dataIntegration.R")
writeMyCopy("numericData.R")
# Clean up - remove functions from workspace
rm(checkFileExists)
rm(writeMyCopy)
cat("... done.\n")
# Open main document in the script pane
file.edit("R-Intro.R")
# [End]