rstudio / packrat

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

Monitor other R-code containing files #51

Closed kevinushey closed 10 years ago

kevinushey commented 10 years ago

We should also look for library calls in .Rmd, .Rnw files.

jmcphers commented 10 years ago

We should share an implementation: https://github.com/rstudio/shinyapps/issues/40

kevinushey commented 10 years ago

We could do something with ad-hoc dispatch like the following:

# ad-hoc dispatch based on the file extension
fileDependencies <- function(file) {
  fileext <- tolower(gsub(".*\\.", "", file))
  switch (fileext,
    r = fileDependencies.R(file),
    rmd = fileDependencies.Rmd(file),
    rnw = fileDependencies.Rnw(file),
    rpres = fileDependencies.Rpres(file),
    stop("Unrecognized file type '", file, "'")
  )
}

This way, we just need to write fileDependencies.R, and functions that extract the relevant code from Rmd, Rnw, Rpres files, then call fileDependencies.R there.

For anything 'markdown' flavored, we have e.g.:

knitr::knit(file, output = tempfile, tangle = TRUE)

(but for packrat we might want to use something standalone; I imagine we can pull R code out with some regexes, or just copy relevant parts of knitr::purl)

For .Rnw, we have Stangle.

jjallaire commented 10 years ago

I'd try to use purl if we can. I know that knitr defines formats in terms of regexes so if need to go the regex route we should get them from knitr, see:

knitr::all_patterns

On Wed, May 14, 2014 at 3:02 PM, Kevin Ushey notifications@github.comwrote:

We could do something with ad-hoc dispatch like the following:

ad-hoc dispatch based on the file extension

fileDependencies <- function(file) { fileext <- tolower(gsub(".*.", "", file)) switch (fileext, r = fileDependencies.R(file), rmd = fileDependencies.Rmd(file), rnw = fileDependencies.Rnw(file), rpres = fileDependencies.Rpres(file), stop("Unrecognized file type '", file, "'") ) }

This way, we just need to write fileDependencies.R, and functions that extract the relevant code from Rmd, Rnw, Rpres files, then call fileDependencies.R there.

For anything 'markdown' flavored, we have e.g.:

knitr::knit(file, output = tempfile, tangle = TRUE)

(but for packrat we might want to use something standalone; I imagine we can pull R code out with some regexes, or just copy relevant parts of knitr::purl)

For .Rnw, we have Stangle.

— Reply to this email directly or view it on GitHubhttps://github.com/rstudio/packrat/issues/51#issuecomment-43123042 .

hadley commented 10 years ago

It wouldn't be a terrible idea to just look for library\((.*?)\) even in knitr/sweave files, since it's unlikely that people will use that in text.

hadley commented 10 years ago

Also need to look in yaml metadata for output formats in packages, e.g. output: rticles::jss_article.

kevinushey commented 10 years ago

(Mostly) handled now, although just parsing as text (instead of forcing a parse of R code) is still an open issue.