使 Subversion 修订号在我的 R 脚本中可见 [英] making the subversion revision number visible in my R scripts
问题描述
我将这个东西放在我的源代码中......(是的,现在只有一个,加上测试脚本).
I'm putting this thing in my source(s)... (right, for now it's just one, plus the test scripts).
REVISION = (function(x) substring(x, first=7, last=nchar(x)-2))("$Rev: 8727 $")
但是真正的"R 程序员是怎么做的呢?
but how do "real" R programmers do?
推荐答案
这是一个很好的解决方案.如果您的数字更少或更多,正则表达式可能更健壮:将开头的 $Rev :
和结尾的 $
交换为空字符串,您应该保留修订版.
That is a pretty good solution. A regular expression may be more robust in case you fewer or more digits: swap the beginnning $Rev :
and the trailing $
for empty strings and you should have the revision left.
每个文件属性的唯一问题是它们仅在此文件本身被 subversion 更新时更新.
The only problem with the per-file properties is that they only update when this file itself is updated by subversion.
出于这个原因(以及许多其他原因),请考虑制作本地包.您的说明文件将 a) 经常更改以适应新版本号,并且 b) 可以简单地通过您添加的新字段进行扩展,例如
For that reason (and many others), consider making a local package. Your DESCRIPTION file will a) change often enough for the new version number and b) can simply be extended by new fields you simply add e.g.
Revision: $Rev$
您可以通过 read.dcf()
从 R 中读取内容,然后您可以执行去除美元符号和冒号的技巧,或使用正则表达式.
You can read the content from R via read.dcf()
after which you can then do your trick of stripping the dollar signs and colon, or use a regular expression.
这篇关于使 Subversion 修订号在我的 R 脚本中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!