Skip to content
Snippets Groups Projects
Commit 5333e92d authored by Svajunas Plunge's avatar Svajunas Plunge
Browse files

get_file_version function added

parent 8180e874
No related branches found
No related tags found
No related merge requests found
Package: SWATdoctR
Type: Package
Title: Finding the right diagnoses and treatments for SWAT+ models
Version: 0.1.24
Version: 0.1.25
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
......@@ -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)
......
......@@ -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)
......
% 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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment