Skip to content

Commit

Permalink
feat: export get_current_version() - fix #39
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 12, 2024
1 parent 19a9732 commit e958e2f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 38 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(filter_by_year)
export(geom_basemap)
export(get_cpr_north_data)
export(get_cpr_south_data)
export(get_current_version)
export(get_forcis_db)
export(get_ocean_names)
export(get_plankton_nets_data)
Expand Down
27 changes: 27 additions & 0 deletions R/get_current_version.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' Get the version of the database currently used
#'
#' @description
#' This function returns the version of the database currently used in the
#' project.
#'
#' @return A `character` of length 1.
#'
#' @export
#'
#' @examples
#' ## ADD EXAMPLE ----

get_current_version <- function() {

if (file.exists(".forcis")) {

config_file <- readLines(".forcis")
in_use_version <- gsub("FORCIS_VERSION=", "", config_file)

} else {

in_use_version <- NULL
}

in_use_version
}
22 changes: 20 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ set_zen_version <- function(version, ask = TRUE) {

if (is.null(version)) {

version <- get_in_use_version()
version <- get_current_version()

if (is.null(version)) {

Expand Down Expand Up @@ -293,4 +293,22 @@ get_zen_latest_version <- function() {
crs_robinson <- function() {
paste0("+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84",
" +units=m +no_defs")
}
}



#' Set/update local database version number in an hidden file .forcis
#'
#' @noRd

set_in_use_version <- function(version) {

saved_version <- get_current_version()

if (is.null(saved_version) || saved_version != version) {
version <- paste0("FORCIS_VERSION=", version)
cat(version, file = ".forcis", append = FALSE, sep = "\n")
}

invisible(NULL)
}
36 changes: 0 additions & 36 deletions R/versions.R

This file was deleted.

18 changes: 18 additions & 0 deletions man/get_current_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e958e2f

Please sign in to comment.