Skip to content

Commit

Permalink
included reload funciton instead of method
Browse files Browse the repository at this point in the history
  • Loading branch information
DSchreyer committed Nov 7, 2024
1 parent 3a21412 commit 899cddb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 51 deletions.
29 changes: 0 additions & 29 deletions R/class-dsoParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,3 @@ setMethod(
})
}
)


#' @title reload function
#' @description
#'
#' Generic for function reload
#'
#' @param object dsoParams config object
#' @export
setGeneric("reload", function(object, ...) standardGeneric("reload"))


#' @title reload dso params
#' @description
#' reloads the current dsoParams config into object
#'
#' @param object dsoParams object
#' @param env environment in which object is located, caller_env() by default
#' @export
setMethod("reload", "dsoParams", function(object, env = caller_env()) {
if (!inherits(object, "dsoParams")) {
stop("The object is not of class 'dsoParams'")
}

var_name <- deparse(substitute(object))
assign(var_name, value = read_params(), envir = env)

invisible(get(var_name, envir = env))
})
2 changes: 1 addition & 1 deletion R/read_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ read_params <- function(stage_path = NULL, return_list = FALSE) {
if (is.null(config_env$stage_dir)) {
stop("stage_path argument missing.")
} else {
cat(paste("reloading from already set stage_path:", config_env$stage_dir))
message(glue::glue("Reloading from already set stage_path: {config_env$stage_dir}"))
stage_path <- config_env$stage_dir
}
}
Expand Down
17 changes: 17 additions & 0 deletions R/reload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' @title Reload dsoParams
#' @description
#' Reloads the current dsoParams configuration into the object.
#'
#' @param params dsoParams object
#' @param env environment in which object is located, caller_env() by default
#' @return The updated dsoParams object.
#' @export
reload <- function(params, env = caller_env()) {
if (!inherits(params, "dsoParams")) {
stop("The object is not of class 'dsoParams'")
}
var_name <- deparse(substitute(params))
assign(var_name, value = read_params(), envir = env)

invisible(get(var_name, envir = env))
}
16 changes: 0 additions & 16 deletions man/reload-dsoParams-method.Rd

This file was deleted.

15 changes: 10 additions & 5 deletions man/reload.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 899cddb

Please sign in to comment.