Last active
May 15, 2016 20:06
-
-
Save dtenenba/50ced940fa48638358cd9cc77627cf52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# two implementations of a function to bump an R package version, given the package name/directory | |
# implementation 1 uses read/write.dcf, but changes lines unnecessarily, even though | |
# we use the keep.white option. | |
bump0 <- function(pkg){ | |
print(pkg) | |
desc <- file.path(pkg, "DESCRIPTION") | |
dcf <- read.dcf(desc) # once without keeping whitespace | |
dcf <- read.dcf(desc, keep.white=colnames(dcf)) | |
vers <- package_version(dcf[,'Version']) | |
vers[1,3] <- (as.integer(vers[1,3])+1) | |
dcf[, "Version"] <- as.character(vers) | |
write.dcf(dcf, desc, keep.white=colnames(dcf)) | |
invsible(NULL) | |
} | |
# implementation 2 should not change anything except the version number, | |
# unless the DESCRIPTION file has windows line endings, in which case they | |
# are all changed. | |
bump <- function(pkg) | |
{ | |
print(pkg) | |
desc <- file.path(pkg, "DESCRIPTION") | |
lines <- readLines(desc) | |
version_idx <- grep("^Version: ", lines) | |
version_line <- lines[version_idx] | |
version_line <- sub("^Version: ", "", version_line) | |
version_line <- trimws(version_line) | |
vers <- package_version(version_line) | |
vers[1,3] <- (as.integer(vers[1,3])+1) | |
lines[version_idx] <- sprintf("Version: %s", as.character(vers)) | |
cat(lines, file=desc, sep="\n") | |
invisible(NULL) | |
} | |
# Determine which packages need to be bumped: | |
# grep -l "VignetteBuilder:.*knitr" */DESCRIPTION | cut -d / -f 1 | sort | uniq > o1 | |
# grep -l "VignetteEngine{ *knitr" */vignettes/* | cut -d / -f 1 | sort | uniq > o2 | |
# cat o1 o2 |sort|uniq > o3 # o3 is the list of packages that need to be bumped | |
# bumpme <- readLines("o3") | |
bump.all <- function(pkgsToBump, manifestFile) | |
{ | |
mf <- readLines(manifestFile) | |
mf <- mf[grep("^Package: ", mf)] | |
mf <- gsub("^Package: ", "", mf) | |
pkgsToBump <- pkgsToBump[pkgsToBump %in% mf] | |
x <- lapply(pkgsToBump, bump) | |
invisible(NULL) | |
} | |
# usage: | |
# bump.all(pkgsToBump, manifestFile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment