Closed kevinushey closed 10 years ago
We should share an implementation: https://github.com/rstudio/shinyapps/issues/40
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
.
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 .
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.
Also need to look in yaml metadata for output formats in packages, e.g. output: rticles::jss_article
.
(Mostly) handled now, although just parsing as text (instead of forcing a parse of R code) is still an open issue.
We should also look for
library
calls in.Rmd
,.Rnw
files.