diff --git a/DESCRIPTION b/DESCRIPTION index e8e6d1b3626d42f850235f16ae9989fc4f161bef..1ef27165bd496bca050531b9845619c1e21c7fc5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,13 @@ License: What license is it under? Encoding: UTF-8 LazyData: true Suggests: + R.utils, + RandomFields, testthat (>= 3.0.0) Config/testthat/edition: 3 Depends: R (>= 2.10) +RoxygenNote: 7.1.1 +Roxygen: list(markdown = TRUE) +Imports: + terra diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000000000000000000000000000000000000..d4e57ad55f6f3c6fd45a5032f39676d915a9a529 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(loadConfig) diff --git a/inst/config.yml b/inst/config.yml new file mode 100644 index 0000000000000000000000000000000000000000..ebdfcb2ef40a6684f722607bdfe12731c7a64598 --- /dev/null +++ b/inst/config.yml @@ -0,0 +1,13 @@ +default: + sic: + path: "*** The path of your installation of SIC should be defined ***" + edisic: "exe/EdiSIC.exe" + talweg: "exe/TALWEG.exe" + fluvia: "exe/FLUVIA.exe" + sirene: "exe/SIRENE.exe" + export: "exe/SicExport.exe" + fortran: + prms: + INTERF: "0" + project: + path: "*** The path of your XML project file should be defined ***" diff --git a/man/loadConfig.Rd b/man/loadConfig.Rd new file mode 100644 index 0000000000000000000000000000000000000000..a441095a16de72f3d0101ca913f6d82632338218 --- /dev/null +++ b/man/loadConfig.Rd @@ -0,0 +1,55 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/loadConfig.R +\name{loadConfig} +\alias{loadConfig} +\title{Read default configuration of the package and complete it with eventual user config} +\usage{ +loadConfig( + sic_path = NULL, + xml_path = NULL, + userFile = "config.yml", + pathDefaultCfg = system.file("config.yml", package = "rsic2") +) +} +\arguments{ +\item{userFile}{location of the user config YML file} + +\item{pathDefaultCfg}{The location of the default configuration (located in "inst/config.yml" of the package by default)} +} +\value{ +A configuration as it is returned by \link[config:get]{config::get}. + +Configuration of RSIC2 as the following structure: +\itemize{ +\item 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: +\itemize{ +\item prms: +\itemize{ +\item INTERF: default \code{INTERF} parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE +} +} +} +\item project +\itemize{ +\item path: Path to the XML project file (should be defined by \code{xml_path} parameter or in the user config file) +} +} +} +\description{ +Read default configuration of the package and complete it with eventual user config +} +\examples{ +library(sic2) +sic_path <- tempdir(check = TRUE) +xml_path <- R.utils::tmpfile() +cfg <- loadConfig(sic_path, xml_path) +str(cfg) +} diff --git a/rsic2.Rproj b/rsic2.Rproj index 497f8bfcfb9d13ad61d14d79963641e9aeab41b0..270314b87d171300f76501b32e8a0354926d9c84 100644 --- a/rsic2.Rproj +++ b/rsic2.Rproj @@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000000000000000000000000000000000000..184d06695f282b11f9707a4497ccde669332e5dc --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(rsic2) + +test_check("rsic2") diff --git a/tests/testthat/test-loadConfig.R b/tests/testthat/test-loadConfig.R new file mode 100644 index 0000000000000000000000000000000000000000..1828a28d496233d58e4c8d7b2a2267329af86675 --- /dev/null +++ b/tests/testthat/test-loadConfig.R @@ -0,0 +1,33 @@ +test_that("incomplete config throw an error", { + expect_error(loadConfig()) +}) + +sic_path <- tempdir(check = TRUE) +xml_path <- tempfile(fileext = ".xml") +writeLines("<XML>Fake project</XML>", xml_path) + +test_that("Wrong SIC path throw an error", { + expect_error(loadConfig(file.path(sic_path, "fake"), xml_path)) +}) + +test_that("Wrong XML path throw an error", { + expect_error(loadConfig(sic_path, file.path(xml_path, "fake.xml"))) +}) + +test_that("SIC and XML paths injected by parameters should be provided in cfg", { + cfg <- loadConfig(sic_path, xml_path) + expect_equal(cfg$sic$path, sic_path) + expect_equal(cfg$project$path, xml_path) +}) + +test_that("SIC and XML paths injected by user yml file should be provided in cfg", { + tmpCfgPath <- tempfile(fileext = ".yml") + ymlCfg <- list(default = list( + sic = list(path = sic_path), + project = list(path = xml_path) + )) + yaml::write_yaml(ymlCfg, tmpCfgPath) + cfg <- loadConfig(userFile = tmpCfgPath) + expect_equal(cfg$sic$path, sic_path) + expect_equal(cfg$project$path, xml_path) +})