2020-09-17 22:48:19 +00:00
|
|
|
# .Rprofile
|
|
|
|
#
|
|
|
|
# This script is automatically executed on startup
|
|
|
|
# ==============================================================================
|
|
|
|
|
2017-08-18 20:04:01 +00:00
|
|
|
init <- function() {
|
2020-09-17 22:48:19 +00:00
|
|
|
|
2020-09-21 04:40:04 +00:00
|
|
|
# Create a local copy of myScript.R if not done yet.
|
2020-09-17 22:48:19 +00:00
|
|
|
if (! file.exists("myScript.R") && file.exists(".tmp.R")) {
|
|
|
|
file.copy(".tmp.R", "myScript.R")
|
|
|
|
cat("A new file \"myScript.R\" was created. You can use it for\n")
|
|
|
|
cat("notes and code experiments.\n\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
cat("\n\n")
|
2020-09-21 04:40:04 +00:00
|
|
|
cat("Please open the file \".myProfile.R\" (click on the file-name in the\n")
|
2020-09-21 04:54:30 +00:00
|
|
|
cat("\"files\" pane), edit it and save it.\n")
|
|
|
|
cat("Then click the checkbox, and use the More -> Move... dialogue\n")
|
|
|
|
cat("to move it into the \"myScripts\" folder.\n\n")
|
2020-09-17 22:48:19 +00:00
|
|
|
|
|
|
|
file.edit("ABC-units.R")
|
|
|
|
return(invisible(NULL))
|
2017-08-18 20:04:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 22:48:19 +00:00
|
|
|
if (! file.exists("./myScripts/.myProfile.R")) {
|
|
|
|
cat("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
|
|
|
|
cat(" =================")
|
|
|
|
cat("\n\n")
|
|
|
|
cat(" WELCOME !\n")
|
|
|
|
cat("\n")
|
|
|
|
cat(" Type 'init()' to begin\n\n")
|
|
|
|
cat("\n")
|
|
|
|
cat(" =================")
|
|
|
|
cat("\n\n")
|
|
|
|
|
2020-09-24 09:47:32 +00:00
|
|
|
} else { # local profile exists ... validate state:
|
2020-09-17 22:48:19 +00:00
|
|
|
cat("\n\nLoading local functions ...")
|
2020-09-24 09:47:32 +00:00
|
|
|
|
2020-09-17 22:48:19 +00:00
|
|
|
source("./myScripts/.myProfile.R")
|
2020-09-24 09:47:32 +00:00
|
|
|
|
|
|
|
if (! exists("myEMail")) { # ... has eMail been defined?
|
|
|
|
cat("ERROR !\n")
|
|
|
|
cat("=======\n")
|
|
|
|
cat("The file \"./myScripts/.myProfile.R\" exists, but\n")
|
|
|
|
cat("the variable \"myEMail\" was not loaded.\n")
|
|
|
|
cat("Please contact your instructor to continue.\n\n")
|
|
|
|
}
|
|
|
|
if (! exists("myStudentNumber")) { # ... has the Student Number been defined?
|
|
|
|
cat("ERROR !\n")
|
|
|
|
cat("=======\n")
|
|
|
|
cat("The file \"./myScripts/.myProfile.R\" exists, but\n")
|
|
|
|
cat("the variable \"myStudentNumber\" was not loaded.\n")
|
|
|
|
cat("Please contact your instructor to continue.\n\n")
|
|
|
|
}
|
|
|
|
if (! grepl("^(100.{7})|(99.{7})$", as.character(myStudentNumber))) {
|
|
|
|
cat("ERROR !\n") # is the Student Number valid?
|
|
|
|
cat("=======\n")
|
|
|
|
cat("The file \"./myScripts/.myProfile.R\" exists, but\n")
|
|
|
|
cat("your Student Number could not be validated.\n")
|
|
|
|
cat("Please examine the file \"./myScripts/.myProfile.R\"\n")
|
|
|
|
cat(" and fix the problem or contact your instructor to continue.\n\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
source(".utilities.R") # local profile appears sane, source utilities
|
|
|
|
|
|
|
|
if (! exists("MYSPE")) { # if MYSPE has not yet been defined, define it now
|
|
|
|
# ... and write it into the profile.
|
|
|
|
prf <- readLines("./myScripts/.myProfile.R")
|
|
|
|
iEmail <- grep("^\\s*myStudentNumber\\s*<-", prf)
|
|
|
|
out <- prf[1:iEmail]
|
2020-09-24 09:50:39 +00:00
|
|
|
out <- c(out, sprintf("MYSPE <- \"%s\" ",
|
2020-09-24 09:47:32 +00:00
|
|
|
getMYSPE(myStudentNumber)))
|
|
|
|
out <- c(out, prf[(iEmail+1):length(prf)])
|
|
|
|
writeLines(out, "./myScripts/.myProfile.R")
|
|
|
|
|
|
|
|
cat("\n")
|
|
|
|
cat(sprintf("MYSPE (%s) was added to \"./myScripts/.myProfile.R\"\n\n",
|
|
|
|
getMYSPE(myStudentNumber)))
|
|
|
|
MYSPE <- getMYSPE(myStudentNumber) # ... define it for immediate use
|
2020-09-24 10:16:41 +00:00
|
|
|
rm(prf, iEmail, out) # cleanup
|
2020-09-24 09:47:32 +00:00
|
|
|
}
|
2020-09-17 22:48:19 +00:00
|
|
|
cat("... done.\n\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default.stringsAsFactors()) {
|
|
|
|
cat("WARNING.\n")
|
|
|
|
cat("========\n")
|
|
|
|
cat("Your default \"stringsAsFactors\" parameter is set to \"TRUE\".\n")
|
|
|
|
cat("This will break some of the code.\n")
|
|
|
|
cat("Please contact your instructor to troubleshoot and fix this issue.\n")
|
|
|
|
cat("\n")
|
|
|
|
}
|
2017-08-18 20:04:01 +00:00
|
|
|
|
2020-09-17 22:48:19 +00:00
|
|
|
# [END]
|