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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: attachment
Title: Deal with Dependencies
Version: 0.4.4
Version: 0.4.5
Authors@R: c(
person("Vincent", "Guyader", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0003-0671-9270")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# attachment 0.4.5

## Bug fixes

- `att_from_examples()` Removed escape characters (`\`) from Roxygen examples.

# attachment 0.4.4

## Patch
Expand Down
4 changes: 4 additions & 0 deletions R/add_from_examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/fake_function.R
Original file line number Diff line number Diff line change
@@ -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()
}
42 changes: 42 additions & 0 deletions tests/testthat/test-att_from_examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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"))

})
Loading