Skip to content

Commit

Permalink
Plecharpent/release/cran (#23)
Browse files Browse the repository at this point in the history
* news update, date , license file

* fix: license

* useless

* update with latests tests results

* fixes: linting, date of release

* fix: no man files generation for unexported function using @nord the the functions doc

Use of library(SticsRFiles) and SticsRFiles::: in tests removed

* fix: some functions doc (internal), removed SticsRFiles::: use in internal functions doc, added SticsRFiles::: in generating XML files vignette

* changes: unwrapping examples for exported functions when possible, with minor correction when needed.

* unwrapping examples for exported functions for testing them using examples path and tempdir() for outputs

* fix: linting issues, examples

* fix: examples

* examples unwrapped and fixed

* donttest replaced by dontrun: checks are failing with github actions !

* added an overwrite argument for forcing to rewrite files types examples folders in tempdir()

* Description content and tidy lines

* fix: examples for set_param_xml avoiding failing files copy in tempdir(), using directly examples files path.
Doc updates.

* fix release date

* removed getwd() from default arg values in functions, man update

* now using message funtion instead of print or cat

* fix: linting issues

* description and can-comments update

* CRAN badge
  • Loading branch information
plecharpent committed Jul 12, 2023
1 parent 7d23739 commit 11df844
Show file tree
Hide file tree
Showing 305 changed files with 821 additions and 4,874 deletions.
16 changes: 7 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SticsRFiles
Title: Read and Modify 'STICS' Input/Output Files
Version: 1.1.3
Date: 2023-06-29
Date: 2023-07-10
Authors@R: c(
person("Patrice", "Lecharpentier", , "patrice.lecharpentier@inrae.fr", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-4044-4322")),
Expand All @@ -22,14 +22,12 @@ Authors@R: c(
person("Joel", "Leonard", role = "rev")
)
Description: Manipulating input and output files of the 'STICS' crop
model. These files are either standard 'JavaSTICS' XML files or more
directly the text files used by the model 'fortran' executable. The
most basic functionality is to read and write parameter names and
values through XML queries, or text files ones. More advanced
functionalities include the generation of input XML from XML templates
and spreadsheets with as many simulations contexts as needed, or the
generation of the input text files from the XML input files for
distributed computing.
model. Files are either 'JavaSTICS' XML files or text files used by
the model 'fortran' executable. Most basic functionalities are reading
or writing parameter names and values in both XML or text input files,
and getting data from output files. Advanced functionalities include
XML files generation from XML templates and/or spreadsheets, or text
files generation from XML files by using 'xslt' transformation.
License: LGPL (>= 3)
URL: https://github.com/SticsRPacks/SticsRFiles,
https://doi.org/10.5281/zenodo.4443206
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export(get_obs)
export(get_param_info)
export(get_param_txt)
export(get_param_xml)
export(get_params_dict)
export(get_plant_txt)
export(get_plants_nb)
export(get_report_results)
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SticsRFiles 1.1.3 _2023-06-29_
# SticsRFiles 1.1.3 _2023-07-10_

* FUNCTIONS
* New function for generating the new_travail.usm STICS file
* New function for generating wheather data file (climat.txt)
* New function for generating weather data files (climat.txt)
* New unit tests added

* FIXES:
Expand Down
14 changes: 8 additions & 6 deletions R/add_node_to_doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,37 @@
#' \dontrun{
#'
#' tec_xml <- file.path(get_examples_path(file_type = "xml"), "file_tec.xml")
#' tec_doc <- SticsRFiles:::xmldocument(tec_xml)
#' tec_doc <- xmldocument(tec_xml)
#'
#' # Getting a new irrigation operation node
#' irrigation_node <- SticsRFiles:::get_xml_base_node("tec", "irrigation")
#' parent_path <- SticsRFiles:::get_param_type(
#' irrigation_node <- get_xml_base_node("tec", "irrigation")
#' parent_path <- get_param_type(
#' tec_doc, "ta", "formalisme",
#' "irrigation"
#' )$xpath
#'
#' # Adding one irrigation operation
#' SticsRFiles:::add_node_to_doc(
#' add_node_to_doc(
#' xml_doc = tec_doc, new_node = irrigation_node,
#' nodes_nb = 1, parent_path = parent_path
#' )
#'
#' # Checking irrigations operations number
#' irrigations_nb <- length(SticsRFiles:::get_param_value(
#' irrigations_nb <- length(get_param_value(
#' tec_doc,
#' "julapI_or_sum_upvt"
#' ))
#' # Fixing it in nb_interventions attribute
#' SticsRFiles:::set_param_value(
#' set_param_value(
#' tec_doc, "nb_interventions", irrigations_nb,
#' "irrigation"
#' )
#' }
#'
#' @keywords internal
#'
#' @noRd
#'
add_node_to_doc <- function(xml_doc, new_node, nodes_nb = 1, parent_path) {

# Checking that parent_path is valid xpath for xml_doc
Expand Down
9 changes: 6 additions & 3 deletions R/add_stics_nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
#' \dontrun{
#'
#' tec_xml <- file.path(get_examples_path(file_type = "xml"), "file_tec.xml")
#' tec_doc <- SticsRFiles:::xmldocument(tec_xml)
#' tec_doc <- xmldocument(tec_xml)
#'
#' # Adding one irrigation operation
#' SticsRFiles:::add_stics_nodes(tec_doc, "irrigation")
#' add_stics_nodes(tec_doc, "irrigation")
#'
#' # Adding three irrigation operations
#' SticsRFiles:::add_stics_nodes(tec_doc, "irrigation", nodes_nb = 3)
#' add_stics_nodes(tec_doc, "irrigation", nodes_nb = 3)
#' }
#'
#' @keywords internal
#'
#' @noRd
#'
add_stics_nodes <- function(xml_doc, formalism_name = NULL, nodes_nb = 1,
stics_version = "latest") {

Expand Down
14 changes: 7 additions & 7 deletions R/all_out_var.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#' }
#' @keywords internal
#'
#' @noRd
#'
all_out_var <- function(stics_version = "latest") {

# Checking and getting the right version
Expand Down Expand Up @@ -68,10 +70,9 @@ all_out_var <- function(stics_version = "latest") {
#' @return A data.frame with information about variable(s) with columns
#' `name`, `definition`, `unit`, `type`
#'
#' @seealso \code{\link{all_out_var}}
#'
#' @examples
#' \dontrun{
#'
#' # Find by variable name (fuzzy search):
#' SticsRFiles::get_var_info("lai")
#'
Expand All @@ -80,7 +81,7 @@ all_out_var <- function(stics_version = "latest") {
#'
#' # Find for a particular version:
#' SticsRFiles::get_var_info("lai", stics_version = "V9.0")
#' }
#'
#'
#' @export
#'
Expand Down Expand Up @@ -137,16 +138,15 @@ get_var_info <- function(var = NULL,
#' @param version `r lifecycle::badge("deprecated")` `version` is no
#' longer supported, use `stics_version` instead.
#'
#' @return A boolean vector: `TRUE` if the variable exist, `FALSE` if it doesn't
#' @return A boolean vector: `TRUE` if the variable exist, `FALSE` otherwise
#'
#' @seealso `get_var_info()` for interactive use.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' is_stics_var(c("lai(n)", "masec(n)", "truc"))
#' }
#' is_stics_var(c("lai(n)", "masec(n)", "unknown"))
#'
is_stics_var <- function(var,
stics_version = "latest",
version = lifecycle::deprecated()) {
Expand Down
8 changes: 5 additions & 3 deletions R/attributes_list2matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' \dontrun{
#'
#' xml_path <- file.path(get_examples_path(file_type = "xml"), "sols.xml")
#' sols_doc <- SticsRFiles:::xmldocument(xml_path)
#' node_set <- SticsRFiles:::get_nodes(sols_doc,
#' sols_doc <- xmldocument(xml_path)
#' node_set <- get_nodes(sols_doc,
#' "//*[@nom=\"solcanne\" or @nom=\"mulchbat\"]")
#' attr_list <- sapply(node_set, function(x) XML::xmlAttrs(x))
#'
Expand All @@ -27,7 +27,7 @@
#' #> format max min nom
#' #> "real" "2.0" "0.0" "mulchbat"
#'
#' SticsRFiles:::attributes_list2matrix(attr_list)
#' attributes_list2matrix(attr_list)
#'
#' #> nom format max min
#' #> [1,] "solcanne" NA NA NA
Expand All @@ -37,6 +37,8 @@
#'
#' @keywords internal
#'
#' @noRd
#'

attributes_list2matrix <- function(attr_list) {
# Getting unique attributes names list
Expand Down
2 changes: 2 additions & 0 deletions R/check_choice_param.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#' @return invisible NULL
#' @keywords internal
#'
#' @noRd
#'
#' @examples
#' \dontrun{
#' check_choice_param(xml_doc = xml_doc, param_name = param_name)
Expand Down
4 changes: 3 additions & 1 deletion R/check_java_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#' }
#'
#' @keywords internal

#'
#' @noRd
#'
check_java_path <- function(javastics) {
if (!file.exists(javastics)) {
stop("The JavaStics folder doesn't exist : ", javastics)
Expand Down
1 change: 1 addition & 0 deletions R/check_java_workspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' @return An absolute JavaSTICS workspace path
#'
#' @keywords internal
#' @noRd

check_java_workspace <- function(javastics, workspace = NULL) {

Expand Down
1 change: 1 addition & 0 deletions R/check_output_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' }
#'
#' @keywords internal
#' @noRd

check_output_files <- function(run_dir, usm_name = NULL) {
if (base::is.null(usm_name)) {
Expand Down
2 changes: 2 additions & 0 deletions R/check_usms_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#'
#' @keywords internal
#'
#' @noRd
#'
#' @examples
#' \dontrun{
#'
Expand Down
4 changes: 3 additions & 1 deletion R/col_names_to_var.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#'
#' @examples
#' col_names <- c("var1", "var2_n", "var3.1.")
#' valid_names <- SticsRFiles:::col_names_to_var(col_names)
#' valid_names <- col_names_to_var(col_names)
#' @keywords internal
#'
#' @noRd
#'
col_names_to_var <- function(var_list = c()) {
. <- NULL

Expand Down
6 changes: 4 additions & 2 deletions R/compute_doy_cumul.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
#'
#' @examples
#' \dontrun{
#' SticsRFiles:::compute_doy_cumul(c(350, 360, 10, 20, 30), c(
#' compute_doy_cumul(c(350, 360, 10, 20, 30), c(
#' 1990, 1990, 1991,
#' 1991, 1991
#' ))
#' }
#'
#' #
#'
#' @keywords internal
#'
#' @noRd
#'
compute_doy_cumul <- function(doys_vec, years_vec) {
if (!all(c(class(doys_vec), class(years_vec)) %in% c("numeric", "integer"))) {
stop("Vectors are not all numeric/integer ones, aborting !")
Expand Down
3 changes: 2 additions & 1 deletion R/convert_xml2txt.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
#' @return None
#'
#' @examples
#'
#' \dontrun{
#' xml_path <- "/path/to/corn_plt.xml"
#' javastics_path <- "/path/to/JavaSTICS/folder"
#' convert_xml2txt(xml_file = xml_path, java_dir = javastics_path)
#' convert_xml2txt(file = xml_path, javastics = javastics_path)
#' }
#'
#' @export
Expand Down
4 changes: 3 additions & 1 deletion R/convert_xml2txt_int.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#' xsl_file <-
#' "/path/to/JavaSTICS/folder/bin/resources/xml/stylesheet/xml2txt.xsl"
#'
#' SticsRFiles:::convert_xml2txt_int(xml_file = xml_plt, style_file = xsl_file)
#' convert_xml2txt_int(xml_file = xml_plt, style_file = xsl_file)
#' }
#'
#' @keywords internal
#'
#' @noRd
#'
convert_xml2txt_int <- function(xml_file, style_file, out_file = NULL) {

f_names <- c(xml_file, style_file)
Expand Down
13 changes: 7 additions & 6 deletions R/download_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' @export
#'
#' @examples
#' \dontrun{
#'
#' # Getting all data
#' download_data()
Expand All @@ -28,7 +27,7 @@
#'
#' # Getting data for a given example : study_case_1 and a given version
#' download_data(example_dirs = "study_case_1", stics_version = "V9.0")
#' }
#'
download_data <- function(out_dir = tempdir(), example_dirs = NULL,
stics_version = "latest",
dir = lifecycle::deprecated(),
Expand Down Expand Up @@ -108,18 +107,20 @@ download_data <- function(out_dir = tempdir(), example_dirs = NULL,
#'
#' @keywords internal
#'
#' @noRd
#'
#' @examples
#' \dontrun{
#' # Getting all available dirs from the data repos
#' SticsRFiles:::get_referenced_dirs()
#' get_referenced_dirs()
#'
#' # Getting dirs for a use case
#' SticsRFiles:::get_referenced_dirs("study_case_1")
#' get_referenced_dirs("study_case_1")
#'
#' # Getting dirs for a use case and a version
#' SticsRFiles:::get_referenced_dirs("study_case_1", "V9.0")
#' get_referenced_dirs("study_case_1", "V9.0")
#'
#' SticsRFiles:::get_referenced_dirs(c("study_case_1", "study_case_2"), "V9.0")
#' get_referenced_dirs(c("study_case_1", "study_case_2"), "V9.0")
#' }
#'
get_referenced_dirs <- function(dirs = NULL, stics_version = NULL) {
Expand Down
18 changes: 4 additions & 14 deletions R/download_usm_xl.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
#' @return A vector of copied files path.
#'
#' @examples
#' \dontrun{
#'
#' download_usm_xl()
#' download_usm_xl(out_dir = "/path/to/destination/dir")
#' }
#'
#'
#' @export
#'
Expand Down Expand Up @@ -66,12 +65,6 @@ download_usm_xl <- function(file = NULL,
dest_dir <- out_dir # to remove when we update inside the function
}

oldw <- getOption("warn")
if (!verbose) {
options(warn = -1)
} else {
options(warn = 0)
}

args <- list(...)

Expand Down Expand Up @@ -115,7 +108,7 @@ download_usm_xl <- function(file = NULL,

if (any(success)) {
if (verbose)
print(paste(files_list[success],
message(paste(files_list[success],
" has been copied in directory ",
dest_dir))
dest_list <- dest_list[success]
Expand All @@ -125,7 +118,6 @@ download_usm_xl <- function(file = NULL,
warning("Error copying files:\n", paste(src_list[!success],
collapse = "\n"))

options(warn = oldw)

return(invisible(dest_list))
}
Expand Down Expand Up @@ -155,9 +147,7 @@ download_usm_xl <- function(file = NULL,
#' @return A vector of copied files path.
#'
#' @examples
#' \dontrun{
#' download_usm_csv(out_dir = "/path/to/destination/dir")
#' }
#' download_usm_csv(out_dir = tempdir())
#'
#' @export
#'
Expand Down
Loading

0 comments on commit 11df844

Please sign in to comment.