Pkgdown: invalid regular expression when building site in Windows 7

Created on 2 Apr 2017  Â·  10Comments  Â·  Source: r-lib/pkgdown

I was just getting started with this package and ran pkgdown::build_site() successfully once, but the next time I tried it I get an R code execution error below (I shortened the file paths with *)

Error in FUN(X[[i]], ...) : 
  invalid regular expression '^C:\Users\A***\Documents\D***\t***\docs$'
In addition: Warning message:
In FUN(X[[i]], ...) : PCRE pattern compilation error
    'PCRE does not support \L, \l, \N{name}, \U, or \u'
    at 'Users\A***\Documents\D***\t***\docs$'

I'm using R 3.3.3 on Windows 7 and just installed roxygen2, and pkgdown from github today. I'm guessing this is a backslash escaping things issue, so is there somewhere I should be adding a file.path() call?

I get an identical error (with Windows filepaths as above since I cloned the repo with my package through git) when I try it on my mac (using osSierra, same versions of R and packages) but only when I try to run the build pkgdown addin from the menu or by keyboard shortcut. If i run pkgdown::build_site(), it works.

Recreating my package from scratch in mac seems to have avoided this issue so it may be a Windows only thing. That is, building the site mac multiple times doesn't result in the invalid regular expression error

bug

All 10 comments

Could you please provide a traceback()?

> traceback()
10: FUN(X[[i]], ...)
9: lapply(patterns, grepl, rfiles_relative, perl = TRUE)
8: ignore_files(rfiles, path)
7: package_files(base_path)
6: parse_package(base_path, load_code, registry, options)
5: roxygen2::roxygenise(pkg$path, roclets = roclets, load_code = ns_env)
4: force(code)
3: withr::with_envvar(r_env_vars(), roxygen2::roxygenise(pkg$path, 
       roclets = roclets, load_code = ns_env))
2: devtools::document()
1: (function () 
   {
       devtools::document()
       build_site(preview = TRUE)
   })()

The source of the problem is roxygen — it looks like you have an invalid regexp in .Rbuildignore.

Had a similar issue. I used pkgdown to add a website, and then used devtools::build() on my package. The package was in the following directory:
C:\Users\gabriel_odom\Documents\GitHub\mvMonitoring\mvMonitoring\

This resulted in the following error:

Error in grepl(e, files, perl = TRUE, ignore.case = TRUE) : 
  invalid regular expression '^C:\Users\gabriel_odom\Documents\GitHub\mvMonitoring\mvMonitoring\docs$'
Execution halted

I reversed the slashes in the .Rbuildignore file, and the package built again.

@hadley @krlmlr I have tracked the problem to usethis

when it is called https://github.com/hadley/pkgdown/blob/7cde4c8525ad1addcb55ddc094ba4cbee9eed180/R/build.r#L207

usethis::use_build_ignore(path)

gives an invalid absolute windows path, for example:

^C:\Users\devin\Documents\Repos\rbabylon\docs$

however correcting it to

+^C:\\Users\devin\Documents\Repos\rbabylon\docs$
-^C:\Users\devin\Documents\Repos\rbabylon\docs$

and it is a valid regex.

By either manually fixing/removing that line document() works again. Likewise, as this is only called if the docs folder doesn't exist, it does not come back as long as someone had built the docs folder at once

I think I may have 'blamed' usethis too soon, it might be the logic to construct the path doesn't build it properly. I'm digging into the path logic and think I can track it down reasonably soon

Ok got it, it is usethis. Using the defaults the base will be ".", therefore normalizePath will be called and at

https://github.com/hadley/pkgdown/blob/7cde4c8525ad1addcb55ddc094ba4cbee9eed180/R/build.r#L202 the path will be absolute

For example, at that point, it is "C:\\Users\\devin\\Documents\\Repos\\rbabylon"

the default behavior of usethis::use_build_ignore is to call escape_path, however, which "naively" escapes, however it needs to maintain the first \\ if it was an absolute path.

Either escape_path could be made more robust, or maybe update to

@hadley If this seems reasonable to you - https://github.com/r-lib/usethis/pull/31 fixes the issue on windows.

I ran into this today. Would it make more sense to just ignore the relative path (docs) or the path argument that gets passed to build_site()?

Adding absolute (Windows) paths means that .Rbuildignore will need to be updated for each user on a repository.

Okay, it looks like the problem is that rel_path() doesn't work on Windows. Going to file a new issue.

pkgdown::rel_path("docs", ".")
#> [1] "C:\\Users\\mahr\\Desktop\\GitRepos\\littlelisteners\\docs"
Was this page helpful?
0 / 5 - 0 ratings