From cb6d901a68aa531bdaef7c56e4dd7a7444e7b859 Mon Sep 17 00:00:00 2001 From: Dorchies David <david.dorchies@irstea.fr> Date: Thu, 17 Mar 2022 12:17:41 +0100 Subject: [PATCH] fix(check): almost all warnings and notes - it still remains one warning on non ASCII character (reported in #10) --- .Rbuildignore | 4 ++++ DESCRIPTION | 4 +++- NAMESPACE | 2 ++ R/create_section_txt.R | 1 + R/create_uniform_reach_txt.R | 2 +- R/dem_to_reach.R | 7 +++++-- R/get_result.R | 31 +++++++++++++++++++++++-------- R/merge_reaches.R | 6 +++--- R/sic_run_fortran.R | 6 ++++-- man/create_uniform_reach_txt.Rd | 2 +- man/dem_to_reach.Rd | 4 +++- man/dem_to_section.Rd | 2 +- man/get_result.Rd | 10 ++++++---- man/get_result_tree.Rd | 13 ++++++++++++- man/merge_reaches.Rd | 8 ++++---- man/read_bin_result_matrix.Rd | 8 +++++++- man/sic_run_fortran.Rd | 2 +- 17 files changed, 81 insertions(+), 31 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 4b3f9f2..d02f20b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,7 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^data-raw$ +^man-roxygen$ +^LICENSE\.md$ +[.]INI$ +^\.gitlab-ci\.yml$ diff --git a/DESCRIPTION b/DESCRIPTION index 11207c5..c27e8ef 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,13 +12,15 @@ LazyData: true Suggests: R.utils, RandomFields, - testthat (>= 3.0.0) + testthat (>= 3.0.0), + yaml Config/testthat/edition: 3 Depends: R (>= 2.10) RoxygenNote: 7.1.2 Roxygen: list(markdown = TRUE) Imports: + config, logger, magrittr, terra, diff --git a/NAMESPACE b/NAMESPACE index ad1a24b..0b1ed7e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,4 +19,6 @@ export(sic_run_export) export(sic_run_fortran) export(split_reach) import(magrittr) +import(utils) import(xml2) +importFrom(stats,dist) diff --git a/R/create_section_txt.R b/R/create_section_txt.R index ed7e759..cd049c6 100644 --- a/R/create_section_txt.R +++ b/R/create_section_txt.R @@ -8,6 +8,7 @@ #' #' @return [character], section description in SIC text import format. #' @export +#' @import utils #' @examples #' # Trapezoidal section #' create_section_txt("Trapeze", 0, "T", list(B = 2, S = 1.5, ZF = 100, ZB = 102)) diff --git a/R/create_uniform_reach_txt.R b/R/create_uniform_reach_txt.R index 2594e8c..f003d0a 100644 --- a/R/create_uniform_reach_txt.R +++ b/R/create_uniform_reach_txt.R @@ -3,7 +3,7 @@ #' @param abscissas [numeric] vector of section abscissas #' @param upstream_bed_elevation [numeric], upstream bed elevation (m) #' @param slope [numeric], bed slope of the reach (m/m) -#' @param names [character] vector of section names +#' @param section_names [character] vector of section names #' @inheritParams create_section_txt #' #' @return A [list] from which each item is a section exported by [create_section_txt]. diff --git a/R/dem_to_reach.R b/R/dem_to_reach.R index 173139f..1350593 100644 --- a/R/dem_to_reach.R +++ b/R/dem_to_reach.R @@ -10,9 +10,10 @@ #' @param start 1-length [numeric], starting value for the chainage (i.e. section abscissa) along the reach #' @param major_bed [logical], `TRUE` for major bed, `FALSE` for minor-medium bed #' -#' @return +#' @return A *ReachTxt* object which is a [list] of *SectionTxt* objects (see [create_section_txt]). #' @rdname dem_to_reach #' @export +#' @importFrom stats dist #' #' @examples #' ## Inputs preparation @@ -60,7 +61,9 @@ dem_to_reach_txt <- function(dem, node_coords, space_step, section_width, nb_poi return(reach_txt) } + #' @rdname dem_to_reach +#' @param section_centers See return value of [get_section_centers] #' @export dem_to_reach <- function(dem, node_coords, section_centers, section_width, nb_points = 50) { lapply(seq_len(nrow(section_centers)), function(i) { @@ -75,7 +78,7 @@ dem_to_reach <- function(dem, node_coords, section_centers, section_width, nb_po #' @inheritParams dem_to_reach #' @param section_center 2-lenght [numeric], coordinates of the section center #' -#' @return +#' @return A [matrix] with the coordinates of the x-z points in the cross-profile section referential #' @export #' #' @inherit dem_to_reach return examples diff --git a/R/get_result.R b/R/get_result.R index b2a4197..8aba75b 100644 --- a/R/get_result.R +++ b/R/get_result.R @@ -1,10 +1,10 @@ -#' Get resultat +#' Get a selection of variables from a simulation result #' #' @inheritParams sic_run_export -#' @param filter -#' @param m +#' @param filters [character] conditions to select columns in result table, see details +#' @param m [matrix] of results produced by [read_bin_result_matrix] #' -#' @return +#' @return [matrix] of results with columns selected by `filters`. #' @export #' @import magrittr #' @@ -50,8 +50,12 @@ get_result <- function(cfg, #' @return [matrix] with the simulation results #' @export #' -#' -read_bin_result_matrix <- function(cfg, scenario, variant) { +#' @examples +#' cfg <- cfg_tmp_project() +#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +#' m <- read_bin_result_matrix(cfg, 1) +#' str(m) +read_bin_result_matrix <- function(cfg, scenario, variant = 0) { file <- paste0( paste(gsub("\\.xml", "", cfg$project$path), scenario, variant, sep = "_"), @@ -86,12 +90,23 @@ read_bin_result_matrix <- function(cfg, scenario, variant) { #' #' @return a [data.frame] with following columns: #' +#' - "bf", "sn", "nd", "pr", "ouv": location of the result with number of respectively reach, section, node, offtake, and device. +#' - "var": the name of the calculated variable +#' - "col": the column number in the matrix produced by [read_bin_result_matrix] +#' +#' @warning +#' Up to now, this function only handle results at sections. +#' #' @export #' @import xml2 #' @import magrittr #' #' @examples -get_result_tree <- function(cfg, scenario, variant) { +#' cfg <- cfg_tmp_project() +#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +#' df <- get_result_tree(cfg, 1) +#' head(df) +get_result_tree <- function(cfg, scenario, variant = 0) { x <- read_xml(cfg$project$path) objs = c("Ouvrage", "Section", "Prise", "Noeud") names(objs) <- objs @@ -126,7 +141,7 @@ get_result_tree <- function(cfg, scenario, variant) { } result_tree_add <- function(df, loc, defcol, cols) { - loc <- utils::modifyList(list(bf = 0, sn = 0, nd = 0, pr = 0, ouv = 0), + loc <- modifyList(list(bf = 0, sn = 0, nd = 0, pr = 0, ouv = 0), loc) return(rbind(df, data.frame(as.data.frame(loc), var = defcol, col = cols))) } diff --git a/R/merge_reaches.R b/R/merge_reaches.R index dd3b317..16c3105 100644 --- a/R/merge_reaches.R +++ b/R/merge_reaches.R @@ -1,8 +1,8 @@ -#' Merge several ReachTxt objects into one +#' Merge several *ReachTxt* objects into one #' -#' @param ... ReachTxt objects +#' @param ... *ReachTxt* objects #' -#' @return +#' @return a *ReachTxt* object (See [create_uniform_reach_txt] and [dem_to_reach]) containing the merged reaches. #' @export #' #' @examples diff --git a/R/sic_run_fortran.R b/R/sic_run_fortran.R index 57c986a..b62ceaf 100644 --- a/R/sic_run_fortran.R +++ b/R/sic_run_fortran.R @@ -7,7 +7,7 @@ #' @details If argument `params` is a [list], arguments are injected in the command line by taking the items of the list with the conversion #' `[key]=[value]`. If argument `params` is a [character] #' -#' @return +#' @return Error code returned by [shell]. #' @export #' #' @examples @@ -27,9 +27,11 @@ sic_run_fortran <- function(prog, params = list(), cfg = loadConfig()) { type = "cmd2" ) logger::log_debug(cmd_line) - shell( + ret <- shell( cmd_line, wait = T, translate = T ) + file.remove("FLUVIA.INI", "SIRENE.INI") + return(ret) } diff --git a/man/create_uniform_reach_txt.Rd b/man/create_uniform_reach_txt.Rd index f47a640..64040f8 100644 --- a/man/create_uniform_reach_txt.Rd +++ b/man/create_uniform_reach_txt.Rd @@ -24,7 +24,7 @@ create_uniform_reach_txt( \item{profile}{\link{list} or \link{matrix}, profile of the section (See details)} -\item{names}{\link{character} vector of section names} +\item{section_names}{\link{character} vector of section names} } \value{ A \link{list} from which each item is a section exported by \link{create_section_txt}. diff --git a/man/dem_to_reach.Rd b/man/dem_to_reach.Rd index 0cbfdd8..828b099 100644 --- a/man/dem_to_reach.Rd +++ b/man/dem_to_reach.Rd @@ -31,9 +31,11 @@ dem_to_reach(dem, node_coords, section_centers, section_width, nb_points = 50) \item{start}{1-length \link{numeric}, starting value for the chainage (i.e. section abscissa) along the reach} \item{major_bed}{\link{logical}, \code{TRUE} for major bed, \code{FALSE} for minor-medium bed} + +\item{section_centers}{See return value of \link{get_section_centers}} } \value{ - +A \emph{ReachTxt} object which is a \link{list} of \emph{SectionTxt} objects (see \link{create_section_txt}). } \description{ The coordinate system of \code{dem} should be a metric orthonormal coordinate system. diff --git a/man/dem_to_section.Rd b/man/dem_to_section.Rd index f3dcd7e..8346460 100644 --- a/man/dem_to_section.Rd +++ b/man/dem_to_section.Rd @@ -18,7 +18,7 @@ dem_to_section(dem, node_coords, section_center, section_width, nb_points = 50) \item{nb_points}{1-length \link{numeric}, number of points to describe cross-section geometries} } \value{ - +A \link{matrix} with the coordinates of the x-z points in the cross-profile section referential } \description{ Create a section cross profile from a DEM diff --git a/man/get_result.Rd b/man/get_result.Rd index a7871bf..55c1ca3 100644 --- a/man/get_result.Rd +++ b/man/get_result.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/get_result.R \name{get_result} \alias{get_result} -\title{Get resultat} +\title{Get a selection of variables from a simulation result} \usage{ get_result( cfg, @@ -19,13 +19,15 @@ get_result( \item{variant}{\link{numeric}, the variant to read} -\item{m}{} +\item{filters}{\link{character} conditions to select columns in result table, see details} + +\item{m}{\link{matrix} of results produced by \link{read_bin_result_matrix}} } \value{ - +\link{matrix} of results with columns selected by \code{filters}. } \description{ -Get resultat +Get a selection of variables from a simulation result } \examples{ cfg <- cfg_tmp_project() diff --git a/man/get_result_tree.Rd b/man/get_result_tree.Rd index d885d1a..f06e1a5 100644 --- a/man/get_result_tree.Rd +++ b/man/get_result_tree.Rd @@ -4,7 +4,7 @@ \alias{get_result_tree} \title{Get correspondence between network object and columns in result binary file} \usage{ -get_result_tree(cfg, scenario, variant) +get_result_tree(cfg, scenario, variant = 0) } \arguments{ \item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} @@ -15,7 +15,18 @@ get_result_tree(cfg, scenario, variant) } \value{ a \link{data.frame} with following columns: +\itemize{ +\item "bf", "sn", "nd", "pr", "ouv": location of the result with number of respectively reach, section, node, offtake, and device. +\item "var": the name of the calculated variable +\item "col": the column number in the matrix produced by \link{read_bin_result_matrix} +} } \description{ Get correspondence between network object and columns in result binary file } +\examples{ +cfg <- cfg_tmp_project() +sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +df <- get_result_tree(cfg, 1) +head(df) +} diff --git a/man/merge_reaches.Rd b/man/merge_reaches.Rd index fa030e3..1ca02aa 100644 --- a/man/merge_reaches.Rd +++ b/man/merge_reaches.Rd @@ -2,18 +2,18 @@ % Please edit documentation in R/merge_reaches.R \name{merge_reaches} \alias{merge_reaches} -\title{Merge several ReachTxt objects into one} +\title{Merge several \emph{ReachTxt} objects into one} \usage{ merge_reaches(...) } \arguments{ -\item{...}{ReachTxt objects} +\item{...}{\emph{ReachTxt} objects} } \value{ - +a \emph{ReachTxt} object (See \link{create_uniform_reach_txt} and \link{dem_to_reach}) containing the merged reaches. } \description{ -Merge several ReachTxt objects into one +Merge several \emph{ReachTxt} objects into one } \examples{ # Minor bed generation diff --git a/man/read_bin_result_matrix.Rd b/man/read_bin_result_matrix.Rd index 760544b..c2e19ea 100644 --- a/man/read_bin_result_matrix.Rd +++ b/man/read_bin_result_matrix.Rd @@ -4,7 +4,7 @@ \alias{read_bin_result_matrix} \title{Read matrix of SIC simulation result file} \usage{ -read_bin_result_matrix(cfg, scenario, variant) +read_bin_result_matrix(cfg, scenario, variant = 0) } \arguments{ \item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} @@ -19,3 +19,9 @@ read_bin_result_matrix(cfg, scenario, variant) \description{ Read matrix of SIC simulation result file } +\examples{ +cfg <- cfg_tmp_project() +sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +m <- read_bin_result_matrix(cfg, 1) +str(m) +} diff --git a/man/sic_run_fortran.Rd b/man/sic_run_fortran.Rd index 3ed6001..04d37b1 100644 --- a/man/sic_run_fortran.Rd +++ b/man/sic_run_fortran.Rd @@ -14,7 +14,7 @@ sic_run_fortran(prog, params = list(), cfg = loadConfig()) \item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} } \value{ - +Error code returned by \link{shell}. } \description{ Run Talweg, Fluvia or Sirene -- GitLab