From 7899a777fef2dd94bb5d530f5ed8ba65db683c08 Mon Sep 17 00:00:00 2001 From: biopsichas <svajunas.plunge@gmail.com> Date: Sun, 5 Feb 2023 13:06:23 +0200 Subject: [PATCH] Fixes to add_kill_op --- .Rbuildignore | 2 +- .gitignore | 2 +- NAMESPACE | 1 + R/helper.R | 4 ++-- man/add_kill_op.Rd | 23 +++++++++++++++++++++++ man/insert_line_at.Rd | 22 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 man/add_kill_op.Rd create mode 100644 man/insert_line_at.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 5b259d4..8042825 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ -test.R \ No newline at end of file +test* \ No newline at end of file diff --git a/.gitignore b/.gitignore index e18bfc4..a84040b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ vignettes/*.pdf # Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html rsconnect/ .Rproj.user -test.R \ No newline at end of file +test* \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index c8e2781..4543aa7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(add_kill_op) export(get_hru_id_by_attribute) export(plot_climate_annual) export(plot_hru_pw_day) diff --git a/R/helper.R b/R/helper.R index e873583..7bb5923 100644 --- a/R/helper.R +++ b/R/helper.R @@ -14,7 +14,6 @@ add_kill_op <- function(project_path){ mgt_sch <- read_lines(paste0(project_path,'/management.sch'), lazy = FALSE) - write_lines(mgt_sch, paste0(project_path,'/management_bak.sch')) l <- 0 while(length(grep("hvkl", mgt_sch)) != 0){ i <- grep("hvkl", mgt_sch)[1] @@ -26,8 +25,9 @@ add_kill_op <- function(project_path){ l <- l+1 } if(l > 0){ + file.copy(paste0(project_path,'/management.sch'), paste0(project_path,'/management_bak.sch')) write_lines(mgt_sch, paste0(project_path,'/management.sch')) - return(paste0(l, " lines were updated in 'management.sch'. Original file is backed up in 'management_bak.sch'.")) + return(paste0(l, " lines were updated (`hvkl` changed to `harv`) and same number added (with `kill` operations) in 'management.sch'. Original file is backed up in 'management_bak.sch'.")) } else { return("No `hvkl` operations exist in 'management.sch'. File was not changed.") } diff --git a/man/add_kill_op.Rd b/man/add_kill_op.Rd new file mode 100644 index 0000000..3ef0d57 --- /dev/null +++ b/man/add_kill_op.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helper.R +\name{add_kill_op} +\alias{add_kill_op} +\title{Replace hvkl operations with harv + kill} +\usage{ +add_kill_op(project_path) +} +\arguments{ +\item{project_path}{Character string, path to the SWAT+ project folder +(i.e. TxtInOut).} +} +\value{ +updated management.sch file +} +\description{ +Replace hvkl operations with harv + kill +} +\examples{ +\dontrun{ +add_kill_op('path_to_your_model') +} +} diff --git a/man/insert_line_at.Rd b/man/insert_line_at.Rd new file mode 100644 index 0000000..10303c5 --- /dev/null +++ b/man/insert_line_at.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helper.R +\name{insert_line_at} +\alias{insert_line_at} +\title{Insert line into character with multiple lines} +\usage{ +insert_line_at(dat, txt, insert_after) +} +\arguments{ +\item{dat}{character with multiple lines} + +\item{txt}{character line to be inserted} + +\item{insert_after}{numeric for line number after, which to insert txt} +} +\value{ +character with multiple lines with inserted new lines +} +\description{ +Insert line into character with multiple lines +} +\keyword{internal} -- GitLab