Commit 63e7a4a9 authored by Dorchies David's avatar Dorchies David
Browse files

fix(loadConfig): forgotten to add the function in the previous commit.

Refs #1
Showing with 56 additions and 13 deletions
+56 -13
#' 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
}
...@@ -21,25 +21,25 @@ A configuration as it is returned by \link[config:get]{config::get}. ...@@ -21,25 +21,25 @@ A configuration as it is returned by \link[config:get]{config::get}.
Configuration of RSIC2 as the following structure: Configuration of RSIC2 as the following structure:
\itemize{ \itemize{
\item sic \item \code{sic}
\itemize{ \itemize{
\item path: Path of local SIC installation (should be defined by \code{sic_path} parameter or in the user config file) \item \code{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 \code{edisic}: sub-path to EdiSIC program
\item talweg: sub-path to TALWEG program \item \code{talweg}: sub-path to TALWEG program
\item fluvia: sub-path to FLUVIA program \item \code{fluvia}: sub-path to FLUVIA program
\item sirene: sub-path to SIRENE program \item \code{sirene}: sub-path to SIRENE program
\item export: sub-path to SicExport program \item \code{export}: sub-path to SicExport program
\item fortran: \item \code{fortran}:
\itemize{ \itemize{
\item prms: \item \code{prms}:
\itemize{ \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{ \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: ...@@ -47,7 +47,7 @@ Configuration of RSIC2 as the following structure:
Read default configuration of the package and complete it with eventual user config Read default configuration of the package and complete it with eventual user config
} }
\examples{ \examples{
library(sic2) library(rsic2)
sic_path <- tempdir(check = TRUE) sic_path <- tempdir(check = TRUE)
xml_path <- R.utils::tmpfile() xml_path <- R.utils::tmpfile()
cfg <- loadConfig(sic_path, xml_path) cfg <- loadConfig(sic_path, xml_path)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment