diff --git a/DESCRIPTION b/DESCRIPTION index 842dddf..c6035fe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: attachment Title: Deal with Dependencies -Version: 0.4.4 +Version: 0.4.5 Authors@R: c( person("Vincent", "Guyader", , "vincent@thinkr.fr", role = c("cre", "aut"), comment = c(ORCID = "0000-0003-0671-9270")), diff --git a/NEWS.md b/NEWS.md index e4c96f0..52d2b75 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# attachment 0.4.5 + +## Bug fixes + +- `att_from_examples()` Removed escape characters (`\`) from Roxygen examples. + # attachment 0.4.4 ## Patch diff --git a/R/add_from_examples.R b/R/add_from_examples.R index b49a39b..d857ca7 100644 --- a/R/add_from_examples.R +++ b/R/add_from_examples.R @@ -27,6 +27,10 @@ att_from_examples <- function(dir.r = "R") { # 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) + +# Clean escape characters + all_examples_clean <- gsub(pattern = "\\\\", replacement = "", x = all_examples_clean) + cat(all_examples_clean, file = roxy_file, sep = "\n") all_deps_examples_data <- attachment::att_from_data(all_examples_clean) diff --git a/tests/testthat/fake_function.R b/tests/testthat/fake_function.R new file mode 100644 index 0000000..fb8a643 --- /dev/null +++ b/tests/testthat/fake_function.R @@ -0,0 +1,14 @@ +#' fake function + +#' @param x a value + +#' @importFrom magrittr %>% +#' @examples +#' library(magrittr) +#' \dontrun{ +#' fakepkg::fun() +#' } +#' @export +my_length <- function(x) { + x %>% length() +} \ No newline at end of file diff --git a/tests/testthat/test-att_from_examples.R b/tests/testthat/test-att_from_examples.R index 7a68059..09ff960 100644 --- a/tests/testthat/test-att_from_examples.R +++ b/tests/testthat/test-att_from_examples.R @@ -22,6 +22,34 @@ my_length <- function(x) { c("magrittr", "fakepkg")) }) + + +test_that("att_from_examples works with escape characters", { + tmpdir <- tempfile("suggestexamples") + + dir.create(file.path(tmpdir, "R"), recursive = TRUE) + + r_file <- file.path(tmpdir, "R", "fun_manual.R") + file.create(r_file) + + writeLines( + text = "#' @importFrom magrittr %>% +#' @examples +#' library(magrittr) +#' fakepkg::fun() +#' 1 %not_in% 1:10 +#' not_null(NULL) +`%not_in%` <- Negate(`%in%`) +", + con = r_file + ) + + expect_equal(att_from_examples(dir.r = file.path(tmpdir, "R")), + c("magrittr", "fakepkg")) + +}) + + test_that("att_from_examples works even with sysdata.rda", { tmpdir <- tempfile("suggestexamples") @@ -48,3 +76,17 @@ my_length <- function(x) { c("magrittr", "fakepkg")) }) + + + +test_that("att_from_examples works with dontrun", { + tmpdir <- tempfile("suggestexamples") + + dir.create(file.path(tmpdir, "R"), recursive = TRUE) + + file.copy(test_path("fake_function.R"),file.path(tmpdir, "R")) + + expect_equal(att_from_examples(dir.r = file.path(tmpdir, "R")), + c("magrittr", "fakepkg")) + +})