rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
401 stars 89 forks source link

Bootstrap seems to fail with Rnw files for knitr #85

Closed jnolis closed 10 years ago

jnolis commented 10 years ago

When I run packrat::bootstrap() for the first time in my project I get the following:

Unable to stangle file 'C:/Users/jadler/[...]/report_A.Rnw'; cannot parse dependencies
Unable to stangle file 'C:/Users/jadler/[...]/report_B.Rnw'; cannot parse dependencies
Unable to stangle file 'C:/Users/jadler/[...]/report_C.Rnw'; cannot parse dependencies
Error in list.files(lib, pattern = paste0("^", pkg, "$"), full.names = TRUE) : 
  invalid 'pattern' regular expression
In addition: There were 15 warnings (use warnings() to see them)

It looks like this might have to do with the fact that the Rnw files I have are were made for use with knitr and not sweave. That explains why the stangle call fails, but I am not sure why that causes the error down the line (if that is even related).

kevinushey commented 10 years ago

Can you elaborate a bit on what you mean by 'for use with knitr'? What do you get if you call packrat:::fileDependencies on those files individually -- do you get a more informative error / warning?

I'm not sure about the error / warnings, but I'll investigate.

jnolis commented 10 years ago

The .Rnw files we make are compiled using the command: knit(".../report_A.Rnw", ".../report_A.tex")

When I run packrat:::fileDependencies on one of the files I get the same error as before: Unable to stangle file '.../report_A.Rnw'; cannot parse dependencies

I highly suspect it's because line 117 of dependencies.R assumes that, since it's a .Rnw file, to determine what the dependencies of the file are it should be treated as though the file is compiled with the Stangle command (and not the knit command). The Stangle command on line 121 fails as the file isn't compatible with sweave. In fact the code to correctly determine the dependencies for this file is essentially already in dependencies.R since it's used for .Rmd files created from knitr (lines 100-115). If that code is taken and used on .Rnw files as well it should work for me. You probably want to do something like "if Stangle fails on an .Rnw try knit on it, otherwise error."

jnolis commented 10 years ago

In fact the particular Stangle call fails because I get: Error in match.arg(options$results, c("verbatim", "tex", "hide")) : 'arg' should be one of “verbatim”, “tex”, “hide” Which I think is due to the fact that Knitr .Rmw files have more options than sweave .Rnw files.

kevinushey commented 10 years ago

That would be it indeed. Thanks for investigating.

jjallaire commented 10 years ago

This PR does what you are suggesting: https://github.com/rstudio/packrat/pull/86

kevinushey commented 10 years ago

The PR has been merged, and both knitr and Sweave are tried when parsing dependencies now.