attachment
attachment copied to clipboard
As user, I'd like attachment to be able to read deps from 'examples' and add them to "suggests"
Validation
- [ ] If I give an example with a package not needed anywhere else, I'd like this package to appear in "Suggests" in DESCRIPTION file
Tech
# Get examples from R files
#' @export
get_from_examples <- function(dir.r = "R") {
rfiles <- list.files(dir.r, full.names = TRUE)
roxy_file <- tempfile("roxy.examples", fileext = ".R")
all_examples <- unlist(lapply(rfiles, function(the_file) {
file_roxytags <- roxygen2::parse_file(the_file)
res <- unlist(
lapply(file_roxytags,
function(x) roxygen2::block_get_tag_value(block = x, tag = "examples"))
)
res
}))
# Clean \dontrun and \donttest, and replace with '{' on next line
all_examples_clean <-
gsub(pattern = "\\\\dontrun\\s*\\{|\\\\donttest\\s*\\{", replacement = "#ICI\n{", x = all_examples)
cat(all_examples_clean, file = roxy_file, sep = "\n")
all_deps_examples <- attachment::att_from_rscript(roxy_file)
file.remove(roxy_file)
return(all_deps_examples)
}
# Add this in att_amend_desc()
if (dir.r != "") {
get_from_examples(dir.r = dir.r)
}