Skip to content

Commit 5714870

Browse files
fix : Remove escape char in att_from_examples (#127)
* fix : Remove escape char in att_from_examples * chore : bump v0.4.5
1 parent 94407af commit 5714870

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: attachment
22
Title: Deal with Dependencies
3-
Version: 0.4.4
3+
Version: 0.4.5
44
Authors@R: c(
55
person("Vincent", "Guyader", , "[email protected]", role = c("cre", "aut"),
66
comment = c(ORCID = "0000-0003-0671-9270")),

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# attachment 0.4.5
2+
3+
## Bug fixes
4+
5+
- `att_from_examples()` Removed escape characters (`\`) from Roxygen examples.
6+
17
# attachment 0.4.4
28

39
## Patch

R/add_from_examples.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ att_from_examples <- function(dir.r = "R") {
2727
# Clean \dontrun and \donttest, and replace with '{' on next line
2828
all_examples_clean <-
2929
gsub(pattern = "\\\\dontrun\\s*\\{|\\\\donttest\\s*\\{", replacement = "#ICI\n{", x = all_examples)
30+
31+
# Clean escape characters
32+
all_examples_clean <- gsub(pattern = "\\\\", replacement = "", x = all_examples_clean)
33+
3034
cat(all_examples_clean, file = roxy_file, sep = "\n")
3135

3236
all_deps_examples_data <- attachment::att_from_data(all_examples_clean)

tests/testthat/fake_function.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#' fake function
2+
3+
#' @param x a value
4+
5+
#' @importFrom magrittr %>%
6+
#' @examples
7+
#' library(magrittr)
8+
#' \dontrun{
9+
#' fakepkg::fun()
10+
#' }
11+
#' @export
12+
my_length <- function(x) {
13+
x %>% length()
14+
}

tests/testthat/test-att_from_examples.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,34 @@ my_length <- function(x) {
2222
c("magrittr", "fakepkg"))
2323

2424
})
25+
26+
27+
test_that("att_from_examples works with escape characters", {
28+
tmpdir <- tempfile("suggestexamples")
29+
30+
dir.create(file.path(tmpdir, "R"), recursive = TRUE)
31+
32+
r_file <- file.path(tmpdir, "R", "fun_manual.R")
33+
file.create(r_file)
34+
35+
writeLines(
36+
text = "#' @importFrom magrittr %>%
37+
#' @examples
38+
#' library(magrittr)
39+
#' fakepkg::fun()
40+
#' 1 %not_in% 1:10
41+
#' not_null(NULL)
42+
`%not_in%` <- Negate(`%in%`)
43+
",
44+
con = r_file
45+
)
46+
47+
expect_equal(att_from_examples(dir.r = file.path(tmpdir, "R")),
48+
c("magrittr", "fakepkg"))
49+
50+
})
51+
52+
2553
test_that("att_from_examples works even with sysdata.rda", {
2654
tmpdir <- tempfile("suggestexamples")
2755

@@ -48,3 +76,17 @@ my_length <- function(x) {
4876
c("magrittr", "fakepkg"))
4977

5078
})
79+
80+
81+
82+
test_that("att_from_examples works with dontrun", {
83+
tmpdir <- tempfile("suggestexamples")
84+
85+
dir.create(file.path(tmpdir, "R"), recursive = TRUE)
86+
87+
file.copy(test_path("fake_function.R"),file.path(tmpdir, "R"))
88+
89+
expect_equal(att_from_examples(dir.r = file.path(tmpdir, "R")),
90+
c("magrittr", "fakepkg"))
91+
92+
})

0 commit comments

Comments
 (0)