Skip to content

Commit

Permalink
Fixing the app_root not resolved correctly issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed May 21, 2024
1 parent b994845 commit cac08ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ravedash
Type: Package
Title: Dashboard System for Reproducible Visualization of 'iEEG'
Version: 0.1.3.28
Version: 0.1.3.29
Authors@R: c(
person("Zhengjia", "Wang", email = "dipterix.wang@gmail.com", role = c("aut", "cre", "cph"))
)
Expand Down
28 changes: 16 additions & 12 deletions R/core-app.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ ensure_template <- function(path, use_cache = TRUE){
normalizePath(path)
}

resolve_app_root <- function(app_root, ensure = FALSE) {
if(missing(app_root) || length(app_root) != 1) {
app_root <- normalizePath(session_root(ensure = ensure), mustWork = FALSE)
} else {
app_root <- normalizePath(app_root, mustWork = FALSE)
}
app_root
}

#' @name rave-session
#' @title Create, register, list, and remove 'RAVE' sessions
#' @param update logical, whether to update to latest 'RAVE' template
Expand Down Expand Up @@ -134,12 +143,7 @@ new_session <- function(update = FALSE, app_root = NULL) {

# create a temporary repository
session_id <- paste0(strftime(Sys.time(), "session-%y%m%d-%H%M%S-%Z-"), toupper(rand_string(4)))
if( length(app_root) == 1 ) {
app_root <- normalizePath(app_root, mustWork = TRUE)
} else {
app_root <- session_root(ensure = TRUE)
app_root <- normalizePath(app_root)
}
app_root <- resolve_app_root(app_root, ensure = TRUE)
app_path <- file.path(app_root, session_id)

# raveio::dir_create2(app_path)
Expand Down Expand Up @@ -205,7 +209,7 @@ new_session <- function(update = FALSE, app_root = NULL) {

logger("A new RAVE session has been created [session ID: { session_id }]", level = "info", use_glue = TRUE)
sess <- use_session(session_id, app_root = app_root)
start_session(session = sess, as_job = FALSE, jupyter = FALSE, dry_run = TRUE, launch_browser = FALSE)
start_session(session = sess, as_job = FALSE, jupyter = FALSE, dry_run = TRUE, launch_browser = FALSE, app_root = app_root)

sess

Expand All @@ -227,11 +231,7 @@ use_session.default <- function(x, app_root = NULL, ...) {
stop("Invalid session ID")
}

if(length(app_root)) {
app_root <- normalizePath(app_root, mustWork = TRUE)
} else {
app_root <- session_root()
}
app_root <- resolve_app_root(app_root)
app_path <- file.path(app_root, x)
app_path <- normalizePath(app_path, mustWork = TRUE)

Expand Down Expand Up @@ -772,6 +772,8 @@ remove_all_sessions <- function() {
#' @export
list_session <- function(path = session_root(), order = c("none", "ascend", "descend")){
order <- match.arg(order)

path <- resolve_app_root(path)
dirs <- list.dirs(path = path, full.names = FALSE, recursive = FALSE)
sel <- grepl("^session-[0-9]{6}-[0-9]{6}-[a-zA-Z]+-[A-Z0-9]{4}$", dirs)
session_ids <- dirs[sel]
Expand All @@ -795,6 +797,8 @@ start_session <- function(
as_job = TRUE, launch_browser = TRUE, single_session = FALSE,
app_root = NULL, dry_run = FALSE) {

app_root <- resolve_app_root(app_root)

if(!missing(session) && length(session)) {
if(isTRUE(new)) {
stop("`start_session`: Please leave `session` blank or NULL if you want to create a new session (new=TRUE).")
Expand Down

0 comments on commit cac08ce

Please sign in to comment.