Introduce initialization function
sma_init() can now be used to load all libraries and the data. It is safe to call sma_init() multiple times. To forcefully reload the data call sma_init_force().
This commit is contained in:
parent
a6b5292890
commit
5e7b6007f1
@ -3,11 +3,8 @@
|
||||
# License: GPL version 3
|
||||
# Jens Mathis Sauer (c) 2020
|
||||
|
||||
library(survival)
|
||||
library(survminer)
|
||||
source("utils.R")
|
||||
|
||||
secmal <- sma_load_data("current.csv")
|
||||
sma_init()
|
||||
|
||||
# Setup survival object
|
||||
surv_dx <- Surv(time = secmal$event_time_dx, event = secmal$event_status)
|
||||
|
||||
39
utils.R
39
utils.R
@ -3,8 +3,6 @@
|
||||
# License: GPL version 3
|
||||
# Jens Mathis Sauer (c) 2020
|
||||
|
||||
library(tidyverse)
|
||||
|
||||
#
|
||||
# Write plot to filename
|
||||
#
|
||||
@ -86,3 +84,40 @@ sma_load_data <- function(file) {
|
||||
# Global break.time.by value
|
||||
#
|
||||
sma_break.time.by = 5 * 365.25
|
||||
|
||||
#
|
||||
# Initialize secMalASCT workspace
|
||||
#
|
||||
# This function can be called multiple times, the data will only
|
||||
# be loaded once. To manually reload data call:
|
||||
# > sma_init_force()
|
||||
#
|
||||
sma_init <- function() {
|
||||
if (exists("sma_initialized") == FALSE) {
|
||||
print("Initialize secMalASCT workspace")
|
||||
|
||||
print("Loading libraries")
|
||||
library(survival)
|
||||
library(survminer)
|
||||
library(tidyverse)
|
||||
|
||||
print("Loading data")
|
||||
#
|
||||
# Use superassignment operator '<<-' to make
|
||||
# secmal and sma_initialized with global scope.
|
||||
#
|
||||
secmal <<- sma_load_data("current.csv")
|
||||
sma_initialized <<- TRUE
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Force reinitialization of workspace
|
||||
#
|
||||
# Forcefully calls sma_init() again.
|
||||
#
|
||||
sma_init_force <- function() {
|
||||
print("Reloading secMalASCT data")
|
||||
remove(sma_initialized, pos = ".GlobalEnv")
|
||||
sma_init()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user