From f2e586c94b26b35b1a2f594e77eaa4e8e7f5313d Mon Sep 17 00:00:00 2001 From: agdamsbo Date: Wed, 10 Oct 2018 15:13:23 +0200 Subject: [PATCH] added auto version numbering --- DESCRIPTION | 2 +- packing.R | 19 ++++++++----------- update local version.R | 13 +++++++++++++ updatePackageVersion.R | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 update local version.R create mode 100644 updatePackageVersion.R diff --git a/DESCRIPTION b/DESCRIPTION index e3ebc21..94c4f12 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: daDoctoR Title: daDoctoR -Version: 0.0.0.9000 +Version: 0.0.0.9003 Authors@R: c( person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) Description: Tools for Danish health research. A collection of diff --git a/packing.R b/packing.R index 984acfa..4126838 100644 --- a/packing.R +++ b/packing.R @@ -3,18 +3,15 @@ library(devtools) # Packing for publication -setwd("/Users/andreas/Documents/GitHub/daDoctoR"); document() +source("/Users/andreas/Documents/GitHub/daDoctoR/updatePackageVersion.R") + +setwd("/Users/andreas/Documents/GitHub/daDoctoR") + +updatePackageVersion() + +document() -setwd(".."); install("daDoctoR") +# Inspiration: "https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/" -# Install from GitHub - -setwd("/"); devtools::install_github('agdamsbo/daDoctoR'); library(daDoctoR) - -"https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/" - -# Fixes - -remove.packages("daDoctoR"); .rs.restartR() diff --git a/update local version.R b/update local version.R new file mode 100644 index 0000000..88f6620 --- /dev/null +++ b/update local version.R @@ -0,0 +1,13 @@ +# Install new version + +# Remove + +remove.packages("daDoctoR") +.rs.restartR() + +# Install from GitHub + +setwd("/") +devtools::install_github('agdamsbo/daDoctoR') + +library(daDoctoR) diff --git a/updatePackageVersion.R b/updatePackageVersion.R new file mode 100644 index 0000000..94760a2 --- /dev/null +++ b/updatePackageVersion.R @@ -0,0 +1,32 @@ +updatePackageVersion <- function(packageLocation ="."){ + ## Read DESCRIPTION file + desc <- readLines(file.path(packageLocation, "DESCRIPTION")) + + ## Find the line where the version is defined + vLine <- grep("^Version\\:", desc) + + ## Extract version number + vNumber <- gsub("^Version\\:\\s*", "", desc[vLine]) + + ## Split the version number into two; a piece to keep, a piece to increment + versionNumber <- strsplit(vNumber, "\\.")[[1]] + versionParts <- length(versionNumber) + vNumberKeep <- paste(versionNumber[1:(versionParts-1)], sep= "", collapse= ".") + vNumberUpdate <- versionNumber[versionParts] + + ## Replace old version number with new one (increment by 1) + oldVersion <- as.numeric(vNumberUpdate) + newVersion <- oldVersion + 1 + + ## Build final version number + vFinal <- paste(vNumberKeep, newVersion, sep = ".") + + ## Update DESCRIPTION file (in R) + desc[vLine] <- paste0("Version: ", vFinal ) + + ## Update the actual DESCRIPTION file + writeLines(desc, file.path(packageLocation, "DESCRIPTION")) + + ## Return the updated version number to screen + return(vFinal) +}