简体   繁体   中英

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,

*pdf                                                                            
*Rdata  

I get the errors:

Warning in readLines(ignore_file) : incomplete final line found on '/home/user/project/.Rbuildignore'

and

invalid regular expression '*pdf'

I thought '*' was a wildcard for one or more characters?

See help(regex) for help on regular expression, esp. the Perl variant, and try

 .*pdf
 .*Rdata

instead. The 'dot' matches any chartacter, and the 'star' says that it can repeat zero or more times. I just tried it on a package of mine and this did successfully ignore a pdf vignette as we asked it to.

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. See ?Sys.glob

You seem to be thinking in terms of globs but .Rbuildignore uses regular expressions. To convert a glob to a regular expression try

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

In a perl regexp, use .*? 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. $ means "end of the path".

* is a quantifier that attaches to a previous expression to allow between 0 and infinite repetitions of it. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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