Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: attachment
Title: Deal with Dependencies
Version: 0.4.2.9002
Version: 0.4.2.9003
Authors@R: c(
person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-1565-9313")),
person("Vincent", "Guyader", , "vincent@thinkr.fr", role = "aut",
comment = c(ORCID = "0000-0003-0671-9270", "previous maintainer")),
person("Vincent", "Guyader", , "vincent@thinkr.fr", role = c("cre", "aut"),
comment = c(ORCID = "0000-0003-0671-9270")),
person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = c("aut"),
comment = c(ORCID = "0000-0002-1565-9313", "previous maintainer")),
person("Murielle", "Delmotte", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-1339-2424")),
person("Swann", "Floc'hlay", , "[email protected]", role = "aut",
Expand All @@ -30,7 +30,7 @@ Config/Needs/website: ThinkR-open/thinkrtemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Language: en-US
Depends:
R (>= 3.4)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
## Patch

- Adding an example using suggest packages to the dummypackage
- `att_from_rmds()` and `att_from_rscript` doesn't search in 'renv' folder anymore

# attachment 0.4.2

Expand Down
14 changes: 13 additions & 1 deletion R/att_from_rmds.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ att_from_rmd <- function(path, temp_dir = tempdir(), warn = -1,
#' @param path path to directory with Rmds or vector of Rmd files
#' @param pattern pattern to detect Rmd files
#' @param recursive logical. Should the listing recurse into directories?
#' @param folder_to_exclude Folder to exclude during scan to detect packages 'renv' by default
#' @inheritParams att_from_rmd
#'
#' @return Character vector of packages called with library or require.
Expand All @@ -94,7 +95,7 @@ att_from_rmd <- function(path, temp_dir = tempdir(), warn = -1,
att_from_rmds <- function(path = "vignettes",
pattern = "*.[.](Rmd|rmd|qmd)$",
recursive = TRUE, warn = -1,
inside_rmd = FALSE, inline = TRUE) {
inside_rmd = FALSE, inline = TRUE,folder_to_exclude = "renv") {

if (isTRUE(all(dir.exists(path)))) {
all_f <- list.files(path, full.names = TRUE, pattern = pattern, recursive = recursive)
Expand All @@ -104,6 +105,17 @@ att_from_rmds <- function(path = "vignettes",
stop("Some files/directories do not exist")
}

if (!is.null(folder_to_exclude) && length(folder_to_exclude) > 0) {
exclude_files <- unlist(lapply(folder_to_exclude, function(folder) {
list.files(path = file.path(path, folder), full.names = TRUE, pattern = pattern, recursive = recursive)
}))

# Exclure les fichiers
all_f <- setdiff(all_f, exclude_files)
}



res <- lapply(all_f,
function(x) att_from_rmd(
x, warn = warn,
Expand Down
14 changes: 12 additions & 2 deletions R/att_from_rscripts.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ att_from_rscript <- function(path) {
#' @param path directory with R scripts inside or vector of R scripts
#' @param pattern pattern to detect R script files
#' @param recursive logical. Should the listing recurse into directories?
#'
#' @param folder_to_exclude Folder to exclude during scan to detect packages. 'renv' by default.
#' @return vector of character of packages names found in the R script
#'
#' @export
Expand All @@ -58,7 +58,7 @@ att_from_rscript <- function(path) {
#' att_from_rscripts(path = file.path(dummypackage, "R"))
#' att_from_rscripts(path = list.files(file.path(dummypackage, "R"), full.names = TRUE))

att_from_rscripts <- function(path = "R", pattern = "*.[.](r|R)$", recursive = TRUE) {
att_from_rscripts <- function(path = "R", pattern = "*.[.](r|R)$", recursive = TRUE, folder_to_exclude = "renv") {

if (isTRUE(all(dir.exists(path)))) {
all_f <- list.files(path, full.names = TRUE, pattern = pattern, recursive = recursive)
Expand All @@ -68,6 +68,16 @@ att_from_rscripts <- function(path = "R", pattern = "*.[.](r|R)$", recursive = T
stop("Some files/directories do not exist")
}

if (!is.null(folder_to_exclude) && length(folder_to_exclude) > 0) {
exclude_files <- unlist(lapply(folder_to_exclude, function(folder) {
list.files(path = file.path(path, folder), full.names = TRUE, pattern = pattern, recursive = recursive)
}))

# Exclure les fichiers
all_f <- setdiff(all_f, exclude_files)
}


lapply(all_f, att_from_rscript) %>%
unlist() %>%
unique() %>%
Expand Down
13 changes: 7 additions & 6 deletions R/create_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extra_dev_pkg <- c(
#' use the default list. Use `NULL` for no extra package.
#' Use `attachment:::extra_dev_pkg` for the list.
#' @param folder_to_include Folder to scan to detect development packages
#' @param folder_to_exclude Folder to exclude during scan to detect packages.'renv' by default
#' @param output Path and name of the file created, default is `./renv.lock`
#' @param install_if_missing Logical. Install missing packages. `TRUE` by default
#' @param document Logical. Whether to run [att_amend_desc()] before
Expand All @@ -47,7 +48,8 @@ extra_dev_pkg <- c(
#' }
create_renv_for_dev <- function(path = ".",
dev_pkg = "_default",
folder_to_include = c("dev", "data-raw"),
folder_to_include = c("dev", "data-raw","renv"),
folder_to_exclude = c("renv"),
output = "renv.lock",
install_if_missing = TRUE,
document = TRUE,
Expand Down Expand Up @@ -116,9 +118,8 @@ create_renv_for_dev <- function(path = ".",

pkg_list <- unique(
c(
att_from_qmds(path = path,recursive = TRUE),
att_from_rmds(path = path,recursive = TRUE),
att_from_rscripts(path = path,recursive = TRUE),
att_from_rmds(path = path,recursive = TRUE, folder_to_exclude = folder_to_exclude),
att_from_rscripts(path = path,recursive = TRUE, folder_to_exclude = folder_to_exclude),
dev_pkg
)
)
Expand All @@ -144,8 +145,8 @@ create_renv_for_dev <- function(path = ".",

# folder_to_include <- folder_to_include[dir.exists(file.path(path, folder_to_include))]

from_r_script <- att_from_rscripts(folder_to_include)
from_rmd <- att_from_rmds(folder_to_include)
from_r_script <- att_from_rscripts(folder_to_include,, folder_to_exclude = folder_to_exclude)
from_rmd <- att_from_rmds(folder_to_include,, folder_to_exclude = folder_to_exclude)

pkg_list <- unique(c(pkg_list, from_r_script, from_rmd))
}
Expand Down
8 changes: 6 additions & 2 deletions man/att_from_rmds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion man/att_from_rscripts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/attachment-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/create_renv_for_dev.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/f3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library(dont.find.me3)
1 change: 1 addition & 0 deletions tests/testthat/f4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library(dont.find.me4)
1 change: 1 addition & 0 deletions tests/testthat/f5.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library(find.me5.from.keep)
46 changes: 46 additions & 0 deletions tests/testthat/test-rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,49 @@ test_that("rmds well parsed", {
})
})




test_that("folder_to_exclude works in att_from_rmds", {


dir_with_Rmd <- tempfile(pattern = "rmds")
dir.create(dir_with_Rmd)
file.copy("f1.Rmd", to = file.path(dir_with_Rmd, "f1.Rmd"))
dir.create(file.path(dir_with_Rmd,"renv"))
dir.create(file.path(dir_with_Rmd,"avoid"))
dir.create(file.path(dir_with_Rmd,"keep"))
file.copy("f1.Rmd", to = file.path(dir_with_Rmd,"renv", "f3.Rmd")) #library(dont.find.me3)
file.copy("f1.Rmd", to = file.path(dir_with_Rmd,"avoid", "f4.Rmd")) #library(dont.find.me4)
file.copy("f1.Rmd", to = file.path(dir_with_Rmd,"keep", "f5.Rmd")) #library(find.me5.from.keep)

cat("
```{r}
library(find.me5.from.keep)
```
",append = TRUE,file = file.path(dir_with_Rmd,"keep", "f5.Rmd"))


cat("
```{r}
library(dont.find.me3)
```
",append = TRUE,file = file.path(dir_with_Rmd,"renv", "f3.Rmd"))

cat("
```{r}
library(dont.find.me4)
```
",append = TRUE,file = file.path(dir_with_Rmd,"avoid", "f4.Rmd"))

res_dir <- att_from_rmds(path = dir_with_Rmd,folder_to_exclude = c("renv","avoid"),recursive = TRUE)

expect_true("find.me5.from.keep" %in% res_dir)
expect_false("dont.find.me3" %in% res_dir)
expect_false("dont.find.me4" %in% res_dir)




})

27 changes: 27 additions & 0 deletions tests/testthat/test-rscript.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,30 @@ test_that("newline correctly escaped", {
expect_true(!"nknitr" %in% newline_script)

})



test_that("folder_to_exclude works in att_from_rscripts", {


dir_with_R <- tempfile(pattern = "rscripts")
dir.create(dir_with_R)
file.copy("f2.R", to = file.path(dir_with_R, "f2.R"))
dir.create(file.path(dir_with_R,"renv"))
dir.create(file.path(dir_with_R,"avoid"))
dir.create(file.path(dir_with_R,"keep"))
file.copy("f3.R", to = file.path(dir_with_R,"renv", "f3.R"))
file.copy("f4.R", to = file.path(dir_with_R,"avoid", "f4.R"))
file.copy("f5.R", to = file.path(dir_with_R,"keep", "f5.R"))
file.copy("f1.Rmd", to = file.path(dir_with_R, "f1.Rmd"))

res_dir <- att_from_rscripts(path = dir_with_R,folder_to_exclude = c("renv","avoid"))

expect_true("find.me5.from.keep" %in% res_dir)
expect_false("dont.find.me3" %in% res_dir)
expect_false("dont.find.me4" %in% res_dir)




})
Loading