Skip to content

Commit

Permalink
now using message funtion instead of print or cat
Browse files Browse the repository at this point in the history
  • Loading branch information
plecharpent committed Jul 7, 2023
1 parent f14eae8 commit c1bdb5d
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 56 deletions.
2 changes: 1 addition & 1 deletion R/download_usm_xl.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ download_usm_xl <- function(file = NULL,

if (any(success)) {
if (verbose)
cat(paste(files_list[success],
message(paste(files_list[success],
" has been copied in directory ",
dest_dir))
dest_list <- dest_list[success]
Expand Down
4 changes: 2 additions & 2 deletions R/file_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ setMethod("exist", signature(object = "file_document"),
}
}
if (!ret & message) {
print(paste0(" File doesn't exist: ", p))
message(paste0(" File doesn't exist: ", p))
}
return(ret)
}
Expand All @@ -184,7 +184,7 @@ setMethod("create", signature(object = "file_document"),
dir.create(p)
}
} else {
print(paste0(" File already exists : ", p))
warning(paste0(" File already exists : ", p))
}
}
)
Expand Down
8 changes: 4 additions & 4 deletions R/gen_ini_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ gen_ini_xml <- function(param_df,
out_idx <- unlist(lapply(xml_docs, base::is.null))

if (any(out_idx)) {
cat("\n")
cat(paste0("Errors have been detected while trying to replace",
" parameters values in xml documents\n"))
cat(paste(sum(!out_idx), "files have been generated !\n"))
message("\nErrors have been detected while trying to replace",
"parameters values in xml documents",
paste(sum(!out_idx), "files have been generated !"),
appendLF = TRUE)
# selecting available documents to produce
xml_docs <- xml_docs[out_idx]
}
Expand Down
8 changes: 4 additions & 4 deletions R/gen_sta_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ gen_sta_xml <- function(param_df,
out_idx <- unlist(lapply(xml_docs, base::is.null))

if (any(out_idx)) {
cat("\n")
cat(paste0("Errors have been detected while trying to replace",
" parameters values in xml documents\n"))
cat(paste(sum(!out_idx), "files have been generated !\n"))
message(paste0("\nErrors have been detected while trying to replace",
"parameters values in xml documents\n"),
paste(sum(!out_idx), "files have been generated !\n"))

# selecting available documents to produce
xml_docs <- xml_docs[out_idx]
}
Expand Down
13 changes: 4 additions & 9 deletions R/gen_tec_doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,17 @@ gen_tec_doc <- function(xml_doc = NULL,
xpath_node
)[[1]])) == "formalisme") {
gen_error <- TRUE
cat(paste(
message(paste(
"The parameter", par_name,
"is unique in the original xml file,",
"and not attached to \"intervention\"\n"
))
cat(paste0("Multiple values are present in input table,",
message(paste0("Multiple values are present in input table,",
" check consistency with formalism definition !\n"))
cat("The treatment for this parameter is aborted.")
cat("\n")
message("The treatment for this parameter has aborted.\n")
next
}

if (par_name == "engrais") {
print("ok for multiple engrais !")
}

# Removing existing nodes, for creating new set of
# after that
remove_parent_from_doc(
Expand All @@ -229,7 +224,7 @@ gen_tec_doc <- function(xml_doc = NULL,
par_form <- get_param_formalisms(xml_doc = xml_doc, par_name)

if (base::is.null(par_form)) {
print(paste("Error: formalism for:", par_name))
message(paste("Error: formalism for:", par_name))
}

# General case, linked to formalisms
Expand Down
7 changes: 3 additions & 4 deletions R/gen_tec_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ gen_tec_xml <- function(param_df = NULL,
out_idx <- unlist(lapply(xml_docs, base::is.null))

if (any(out_idx)) {
cat("\n")
cat(paste0("Errors have been detected while trying to replace",
"parameters values in xml documents\n"))
cat(paste(sum(!out_idx), "files have been generated !\n"))
message(paste0("\nErrors have been detected while trying to replace",
"parameters values in xml documents\n"),
paste(sum(!out_idx), "files have been generated !\n"))
# selecting available documents to produce
xml_docs <- xml_docs[out_idx]
}
Expand Down
2 changes: 1 addition & 1 deletion R/get_file_int.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ get_file_int <- function(workspace,
plant_name = NULL,
verbose = TRUE) {

if (verbose) print(filename)
if (verbose) message(filename)

if (is.list(filename)) filename <- unlist(filename)
if (is.list(plant_name)) plant_name <- unlist(plant_name)
Expand Down
2 changes: 1 addition & 1 deletion R/get_param_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ get_param_value <- function(xml_doc,
value <- NULL

if (show_xpath) {
print(xpath)
message(xpath)
}

if (base::is.null(xpath)) {
Expand Down
2 changes: 1 addition & 1 deletion R/get_params_from_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ get_params_from_table <- function(params_table,
if (stopping) {
stop(message_str)
} else {
cat(message_str)
message(message_str)
}

# removing unknown param columns
Expand Down
2 changes: 1 addition & 1 deletion R/manage_stics_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ add_stics_version <- function(version_name,
)

if (verbose)
cat(paste0(version_name,
message(paste0(version_name,
" successfully set in SticsRFiles ",
location,
".\n"))
Expand Down
4 changes: 2 additions & 2 deletions R/remove_node_from_doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ remove_node_from_doc <- function(xml_doc, param_name,

# if the type does not exist
if (base::is.null(xpath_node)) {
print(paste("Unknown parameter in xml doc: ", param_name))
message(paste("Unknown parameter in xml doc: ", param_name))
return(invisible())
}

Expand All @@ -65,7 +65,7 @@ remove_node_from_doc <- function(xml_doc, param_name,
}

if (base::is.null(xml_nodes)) {
print("No nodes to remove from xml doc !")
message("No nodes to remove from xml doc !")
return(invisible())
}

Expand Down
4 changes: 2 additions & 2 deletions R/replace_txt_param_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ replace_txt_param_value <- function(file_path,
diff_files <- as.numeric(diff_files)
not_replaced_files <- diff_files == 0
if (any(not_replaced_files)) {
print("No replacement for file(s):")
print(out_file_path[not_replaced_files])
message("No replacement for file(s):")
message(out_file_path[not_replaced_files])
}
# removing the temporary file
if (in_place) {
Expand Down
2 changes: 1 addition & 1 deletion R/set_param_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ set_param_value <- function(xml_doc,
xpath <- param_type$xpath

if (show_xpath) {
print(xpath)
message(xpath)
}


Expand Down
2 changes: 1 addition & 1 deletion R/stics_examples_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ get_examples_path <- function(file_type, stics_version = "latest",

# If not any arguments : displaying files types list
if (missing(file_type)) {
cat("Available files types: ", paste(get_examples_types(), collapse = ","))
message("Available files types: ", paste(get_examples_types(), collapse = ","))
return(invisible())
}

Expand Down
42 changes: 21 additions & 21 deletions R/upgrade_workspace_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ upgrade_workspace_xml <- function(workspace,

# Testing the workspace dir to be converted
if (!dir.exists(workspace) ||
!file.exists(file.path(workspace, "usms.xml"))) {
!file.exists(file.path(workspace, "usms.xml"))) {
stop(
workspace,
": the directory does not exist or is not a JavaSTICS workspace !"
Expand All @@ -105,7 +105,7 @@ upgrade_workspace_xml <- function(workspace,

# Testing the JavaSTICS dir
if (!dir.exists(javastics) ||
!file.exists(file.path(javastics, "JavaStics.exe"))) {
!file.exists(file.path(javastics, "JavaStics.exe"))) {
stop(
javastics,
" : the directory does nor exist or is not a JavaSTICS one !"
Expand All @@ -114,13 +114,12 @@ upgrade_workspace_xml <- function(workspace,


if (verbose) {
cat(paste(
message(paste(
"Upgrading files from version", stics_version, "to",
target_version, "\n"
))
cat(paste("From: ", workspace, "\n"))
cat(paste("To: ", out_dir, "\n"))
cat("-----------------------------------\n")
target_version, "\n"),
paste("From: ", workspace, "\n"),
paste("To: ", out_dir, "\n"),
"-----------------------------------\n")
}

# Converting param_gen.xml
Expand All @@ -135,7 +134,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("param_gen.xml\n")
message("param_gen.xml\n")
}
}

Expand Down Expand Up @@ -166,7 +165,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("param_new_form.xml\n")
message("param_new_form.xml\n")
}
}

Expand All @@ -186,7 +185,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("usms.xml\n")
message("usms.xml\n")
}

# Converting sols.xml file
Expand All @@ -203,7 +202,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("sols.xml\n")
message("sols.xml\n")
}

# Converting station files (*_sta.xml)
Expand All @@ -221,7 +220,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("*_sta.xml\n")
message("*_sta.xml\n")
}

# Converting initialisation files (*_ini.xml)
Expand All @@ -239,7 +238,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("*_ini.xml\n")
message("*_ini.xml\n")
}

# Converting crop management files (*_tec.xml)
Expand All @@ -258,7 +257,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("*_tec.xml\n")
message("*_tec.xml\n")
}

# Copying *.mod files (for model outputs)
Expand All @@ -268,7 +267,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("Copying *.mod files.\n")
message("Copying *.mod files.\n")
}

# TODO: see how to manage variables names checks in *.mod files
Expand All @@ -287,7 +286,7 @@ upgrade_workspace_xml <- function(workspace,
)

if (verbose) {
cat("Copying *.obs files.\n")
message("Copying *.obs files.\n")
}

# Copying weather data files
Expand All @@ -310,7 +309,7 @@ upgrade_workspace_xml <- function(workspace,
}

if (verbose) {
cat("Copying weather files.\n")
message("Copying weather files.\n")
}


Expand All @@ -324,7 +323,7 @@ upgrade_workspace_xml <- function(workspace,

if (length(plant_files) > 0) {
if (verbose) {
cat("*_plt.xml\n")
message("*_plt.xml\n")
}

# For creating a sub-directory in workspace for upgraded plant files
Expand All @@ -345,7 +344,8 @@ upgrade_workspace_xml <- function(workspace,
}

if (verbose) {
cat("-----------------------------------\n")
message(paste0("-----------------------------------\n",
"Files upgrade and copy is complete.\n")
)
}
cat("Files upgrade and copy is complete.\n")
}
2 changes: 1 addition & 1 deletion R/xml_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ setMethod(
# testing if all nodes have the same attributes !!
if (!is.matrix(attr_list) && !is.matrix(attr_list[, ])) {
if (object@warn) {
print(class(attr_list))
message(class(attr_list))
warning(paste(
"Existing nodes with different attributes comparing to others,",
"missing attributes ?",
Expand Down

0 comments on commit c1bdb5d

Please sign in to comment.