Skip to content

Commit

Permalink
only support ::, not :::
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-sauer committed Nov 11, 2024
1 parent 77483e5 commit 7b1ebc5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(.testPrepExtendedComment)
export(addMapping)
export(cacheCleanup)
export(cacheCopy)
Expand Down
10 changes: 7 additions & 3 deletions R/prepExtendedComment.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ prepExtendedComment <- function(x, type = "#undefined", warn = TRUE, n = 1) {

# if readSource is called as madrat::readSource functionName will
# be in this unintuitive order c("::", "madrat", "readSource")
if (length(functionCall) == 3 && functionCall[[1]] %in% c("::", ":::")) {
if (length(functionCall) == 3 && functionCall[[1]] == "::") {
f <- get(functionCall[[3]], envir = loadNamespace(functionCall[[2]]), mode = "function", sys.frame(-n - 1))
} else {
f <- get(functionCall, mode = "function", sys.frame(-n - 1))
Expand Down Expand Up @@ -60,7 +60,11 @@ prepExtendedComment <- function(x, type = "#undefined", warn = TRUE, n = 1) {
return(extendedComment)
}

# this exists only for testing purposes
testPrepExtendedComment <- function() {
#' .testPrepExtendedComment
#'
#' This function exists only for testing purposes.
#'
#' @export
.testPrepExtendedComment <- function() {
return(prepExtendedComment(list(unit = "m", description = "example", package = "blub")))
}
11 changes: 11 additions & 0 deletions man/dot-testPrepExtendedComment.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-prepExtendedComment.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("prepExtendedComment works in functions called via package::fun", {
# need to run in separate R session to make sure madrat is not attached / loaded via load_all
expect_identical(callr::r(function() madrat:::testPrepExtendedComment()[1:2]),
expect_identical(callr::r(function() madrat::.testPrepExtendedComment()[1:2]),
c(" description: example",
" unit: m"))
})

0 comments on commit 7b1ebc5

Please sign in to comment.