Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
swatdoctr
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Schürz
swatdoctr
Commits
5333e92d
Commit
5333e92d
authored
8 months ago
by
Svajunas Plunge
Browse files
Options
Downloads
Patches
Plain Diff
get_file_version function added
parent
8180e874
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
DESCRIPTION
+2
-2
2 additions, 2 deletions
DESCRIPTION
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/helper.R
+27
-0
27 additions, 0 deletions
R/helper.R
man/get_file_version.Rd
+29
-0
29 additions, 0 deletions
man/get_file_version.Rd
with
59 additions
and
2 deletions
DESCRIPTION
+
2
−
2
View file @
5333e92d
Package: SWATdoctR
Type: Package
Title: Finding the right diagnoses and treatments for SWAT+ models
Version: 0.1.2
4
Version: 0.1.2
5
Author: c(person("Christoph", "Schürz",
email = "christoph.schuerz@ufz.de",
role = c("aut", "cre")),
...
...
@@ -34,4 +34,4 @@ Suggests:
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.
1
RoxygenNote: 7.3.
2
This diff is collapsed.
Click to expand it.
NAMESPACE
+
1
−
0
View file @
5333e92d
...
...
@@ -3,6 +3,7 @@
export(add_kill_op)
export(check_hru_waterbalance)
export(filter_hru_at_harvkill)
export(get_file_version)
export(get_hru_id_by_attribute)
export(plot_basin_var)
export(plot_climate_annual)
...
...
This diff is collapsed.
Click to expand it.
R/helper.R
+
27
−
0
View file @
5333e92d
...
...
@@ -114,6 +114,33 @@ remove_tail <- function(f, pattern){
return
(
f
)
}
#' Get the Highest Version Number of a File
#'
#' This function searches for files in a specified directory that match a given
#' pattern and extracts the highest version number from those files.
#'
#' @param parent_dir A string representing the path to the directory where the
#' files are located.
#' @param file_name A string representing the setup name.
#' @param add A string to be added to the file name pattern to match.
#' @return The highest version number found among the matching files as a
#' numeric value. Returns 0 if no matching files are found.
#' @export
#' @examples
#' \dontrun{
#' file_version <- get_file_version(parent_dir, save_name, '_nostr_') + 1
#' }
get_file_version
<-
function
(
parent_dir
,
file_name
,
add
)
{
files
<-
list.files
(
path
=
parent_dir
,
pattern
=
paste0
(
file_name
,
add
,
'\\d{1,2}'
,
'\\.rds'
))
vers_val
<-
as.numeric
(
gsub
(
paste
(
file_name
,
add
,
'\\.rds'
,
sep
=
'|'
),
''
,
files
))
return
(
max
(
vers_val
,
0
))
}
#' @keywords internal
lwr
<-
function
(
df
){
names
(
df
)
<-
tolower
(
names
(
df
))
return
(
df
)
...
...
This diff is collapsed.
Click to expand it.
man/get_file_version.Rd
0 → 100644
+
29
−
0
View file @
5333e92d
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helper.R
\name{get_file_version}
\alias{get_file_version}
\title{Get the Highest Version Number of a File}
\usage{
get_file_version(parent_dir, file_name, add)
}
\arguments{
\item{parent_dir}{A string representing the path to the directory where the
files are located.}
\item{file_name}{A string representing the setup name.}
\item{add}{A string to be added to the file name pattern to match.}
}
\value{
The highest version number found among the matching files as a
numeric value. Returns 0 if no matching files are found.
}
\description{
This function searches for files in a specified directory that match a given
pattern and extracts the highest version number from those files.
}
\examples{
\dontrun{
file_version <- get_file_version(parent_dir, save_name, '_nostr_') + 1
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment