added auto version numbering

This commit is contained in:
agdamsbo 2018-10-10 15:13:23 +02:00
parent 1c1e76414a
commit f2e586c94b
4 changed files with 54 additions and 12 deletions

View File

@ -1,6 +1,6 @@
Package: daDoctoR Package: daDoctoR
Title: daDoctoR Title: daDoctoR
Version: 0.0.0.9000 Version: 0.0.0.9003
Authors@R: c( Authors@R: c(
person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut")))
Description: Tools for Danish health research. A collection of Description: Tools for Danish health research. A collection of

View File

@ -3,18 +3,15 @@ library(devtools)
# Packing for publication # 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()

13
update local version.R Normal file
View File

@ -0,0 +1,13 @@
# Install new version
# Remove
remove.packages("daDoctoR")
.rs.restartR()
# Install from GitHub
setwd("/")
devtools::install_github('agdamsbo/daDoctoR')
library(daDoctoR)

32
updatePackageVersion.R Normal file
View File

@ -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)
}