简体   繁体   English

为什么'*'在我的.Rbuildignore文件中不能作为perl regexp工作?

[英]Why doesn't '*' work as a perl regexp in my .Rbuildignore file?

When I try to build a package with the following in my .Rbuildignore file, 当我尝试在我的.Rbuildignore文件中构建包含以下内容的包时,

*pdf                                                                            
*Rdata  

I get the errors: 我得到错误:

Warning in readLines(ignore_file) : incomplete final line found on '/home/user/project/.Rbuildignore' readLines(ignore_file)中的警告:在'/home/user/project/.Rbuildignore'上找到不完整的最后一行

and

invalid regular expression '*pdf' 无效的正则表达式'* pdf'

I thought '*' was a wildcard for one or more characters? 我以为'*'是一个或多个角色的通配符?

See help(regex) for help on regular expression, esp. 有关help(regex)的帮助,请参阅help(regex) ,尤其是 the Perl variant, and try Perl变种,并尝试

 .*pdf
 .*Rdata

instead. 代替。 The 'dot' matches any chartacter, and the 'star' says that it can repeat zero or more times. 'dot'匹配任何图表,'star'表示它可以重复零次或多次。 I just tried it on a package of mine and this did successfully ignore a pdf vignette as we asked it to. 我只是尝试了我的一个包,这确实忽略了我们要求的pdf插图。

There are two styles of pattern matching for files: 文件的模式匹配有两种样式:

  1. regular expressions. 常用表达。 These are used for general string pattern matching. 这些用于一般字符串模式匹配。 See ?regex 看?正则表达式
  2. globs. 水珠。 These are typically used by UNIX shells. 这些通常由UNIX shell使用。 See ?Sys.glob 见?Sys.glob

You seem to be thinking in terms of globs but .Rbuildignore uses regular expressions. 你似乎在考虑使用globs,但是.Rbuildignore使用正则表达式。 To convert a glob to a regular expression try 要将glob转换为正则表达式,请尝试

> glob2rx("*pdf")
[1] "^.*pdf$"

In a perl regexp, use .*? 在perl regexp中,使用.*? as a wildcard. 作为通配符。

But I think that what you actually want is pdf$ and Rdata$ as entries in .Rbuildignore seem to affect files whose paths they match only partially, too. 但我认为你真正想要的是pdf$Rdata$因为Rdata$中的条目似乎也影响了它们只匹配部分路径的文件。 $ means "end of the path". $表示“路径的终点”。

* is a quantifier that attaches to a previous expression to allow between 0 and infinite repetitions of it. *是一个量化器,它附加到前一个表达式,允许在0和无限重复之间。 Since you have not preceded the quantifier with an expression, this is an error. 由于您没有在量词之前加上表达式,因此这是一个错误。

. is an expression that matches any character. 是一个匹配任何字符的表达式。 So I suspect that you want .*pdf , .*Rdata , etc. 所以我怀疑你想要.*pdf.*Rdata

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM