diff --git a/R/loadConfig.R b/R/loadConfig.R new file mode 100644 index 0000000000000000000000000000000000000000..418d78c81412040fe25441dd203802b3f84934a8 --- /dev/null +++ b/R/loadConfig.R @@ -0,0 +1,43 @@ +#' Read default configuration of the package and complete it with eventual user config +#' +#' @param userFile location of the user config YML file +#' @param pathDefaultCfg The location of the default configuration (located in "inst/config.yml" of the package by default) +#' +#' @return A configuration as it is returned by [config::get]. +#' +#' Configuration of RSIC2 as the following structure: +#' +#' - `sic` +#' - `path`: Path of local SIC installation (should be defined by `sic_path` parameter or in the user config file) +#' - `edisic`: sub-path to EdiSIC program +#' - `talweg`: sub-path to TALWEG program +#' - `fluvia`: sub-path to FLUVIA program +#' - `sirene`: sub-path to SIRENE program +#' - `export`: sub-path to SicExport program +#' - `fortran`: +#' - `prms`: +#' - `INTERF`: default `INTERF` parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE +#' - `project` +#' - `path`: Path to the XML project file (should be defined by `xml_path` parameter or in the user config file) +#' +#' @export +#' +#' @examples +#' library(rsic2) +#' sic_path <- tempdir(check = TRUE) +#' xml_path <- R.utils::tmpfile() +#' cfg <- loadConfig(sic_path, xml_path) +#' str(cfg) +loadConfig <- function(sic_path = NULL, xml_path = NULL, userFile = "config.yml", pathDefaultCfg = system.file("config.yml", package = "rsic2")) { + cfg <- config::get(file = pathDefaultCfg) + if (file.exists(userFile)) {cfg = config::merge(cfg,config::get(file = userFile))} + if (!is.null(sic_path)) cfg$sic$path <- sic_path + if (!is.null(xml_path)) cfg$project$path <- xml_path + if (!dir.exists(cfg$sic$path)) { + stop("Path for SIC is undefined or does not exist: ", cfg$sic$path) + } + if (!file.exists(cfg$project$path)) { + stop("Path for XMLproject file is undefined or the file does not exist: ", cfg$project$path) + } + cfg +} diff --git a/man/loadConfig.Rd b/man/loadConfig.Rd index a441095a16de72f3d0101ca913f6d82632338218..9106a7da1d7b52a50e6f7d838cb0925faccc2b33 100644 --- a/man/loadConfig.Rd +++ b/man/loadConfig.Rd @@ -21,25 +21,25 @@ A configuration as it is returned by \link[config:get]{config::get}. Configuration of RSIC2 as the following structure: \itemize{ -\item sic +\item \code{sic} \itemize{ -\item path: Path of local SIC installation (should be defined by \code{sic_path} parameter or in the user config file) -\item edisic: sub-path to EdiSIC program -\item talweg: sub-path to TALWEG program -\item fluvia: sub-path to FLUVIA program -\item sirene: sub-path to SIRENE program -\item export: sub-path to SicExport program -\item fortran: +\item \code{path}: Path of local SIC installation (should be defined by \code{sic_path} parameter or in the user config file) +\item \code{edisic}: sub-path to EdiSIC program +\item \code{talweg}: sub-path to TALWEG program +\item \code{fluvia}: sub-path to FLUVIA program +\item \code{sirene}: sub-path to SIRENE program +\item \code{export}: sub-path to SicExport program +\item \code{fortran}: \itemize{ -\item prms: +\item \code{prms}: \itemize{ -\item INTERF: default \code{INTERF} parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE +\item \code{INTERF}: default \code{INTERF} parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE } } } -\item project +\item \code{project} \itemize{ -\item path: Path to the XML project file (should be defined by \code{xml_path} parameter or in the user config file) +\item \code{path}: Path to the XML project file (should be defined by \code{xml_path} parameter or in the user config file) } } } @@ -47,7 +47,7 @@ Configuration of RSIC2 as the following structure: Read default configuration of the package and complete it with eventual user config } \examples{ -library(sic2) +library(rsic2) sic_path <- tempdir(check = TRUE) xml_path <- R.utils::tmpfile() cfg <- loadConfig(sic_path, xml_path)