问题描述
我发现自己在更新,我保持经常的R包的版本和日期。这两个版本和日期的描述存在,的packageName-package.Rd也是人/的packageName-package.Rd。我忘了在一个文件中多次更新。这些原先由package.skeleton命令生成。是否有一个类似的命令/实用脚本来更新版本?
I'm finding myself updating a the version and date of the r-packages that I maintain quite often. Both the version and date exists in DESCRIPTION, packageName-package.Rd and also man/packageName-package.Rd. I've forgotten to update in one file several times. These were originally generated by the package.skeleton command. Is there a similar command/utility script to update the version?
编辑:经仔细检查不需要在Rd文件自动生成的版本和日期。正确的日期和版本仍然出现生成的说明书中无。所以,很显然,这给只有一个地方可更新此信息。
Upon closer inspection the automatically generated versions and dates in the Rd files are not needed. The correct date and version still appears in the generated manual. So obviously this leave only one place to update this information.
推荐答案
保罗Hiemstra的想法似乎对我非常有用,所以我写的codeS那几行:
Paul Hiemstra's idea seemed very useful to me, so I wrote those few lines of codes:
upVers <- function(path,update="snapshot",date=TRUE,simplify=TRUE)
{
# This function updates the description file from package
# in path (assumed work directory by default, as typical
# with projects in RStudio using GitHub).
# Usage:
# path: path to contents of a package
# update: What to update? "version", "major", "minor", "snapshot"
# date: Update date as well?
# simplfy: omit trailing zeros?
# Assumes following numbering system:
# version.major.minor-snapshot
uplist <- c("version","major","minor","snapshot")
if (missing(path)) path <- getwd()
DESCfile <- paste0(path,"/DESCRIPTION")
if (!file.exists(DESCfile)) stop("DESCRIPTION does not exist. Is this the folder of a package?")
DESC <- readLines(DESCfile)
### Update date:
if (date)
{
DESC <- gsub("(?<=Date: )\\d{4}-\\d{2}-\\d{2}",Sys.Date(),DESC,perl=TRUE)
}
### Update version:
Vers <- regmatches(DESC,regexpr("(?<=Version: )\\d+\\.?\\d*\\.?\\d*\\-?\\d*",DESC,perl=TRUE))
Vers <- as.numeric(unlist(strsplit(Vers,split="\\.|\\-")))
Vers <- c(Vers,rep(0,length=4-length(Vers)))
Vers[grep(update,uplist,ignore.case=TRUE)] <- Vers[grep(update,uplist,ignore.case=TRUE)] + 1
Vers[1:4>grep(update,uplist,ignore.case=TRUE)] <- 0
# Combine and replace:
Vers <- paste(paste(Vers[1:3],collapse="."),Vers[4],sep="-")
if (simplify)
{
Vers <- gsub("\\.?0?\\.?0?\\-?0?$","",Vers)
}
DESC <- gsub("(?<=Version: )\\d+\\.?\\d*\\.?\\d*\\-?\\d*",Vers,DESC,perl=TRUE)
# Write Description:
writeLines(DESC,DESCfile)
}
此功能在使用版本编号系统更新说明
文件 version.major.minor快照
,默认情况下快照和日期被更新。例如:
This function updates the DESCRIPTION
file using a version numbering system version.major.minor-snapshot
, by default the snapshot and date are updated. For example:
# An R package:
f <- function() "foo"
package.skeleton("Foo","f")
# Update:
upVers("Foo")
# DESCIRPTION now shows version number 1.0.0-1
这篇关于是否有可能参数A R包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!