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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## CHANGES

## BUGFIXES
* Fixed runtime error when `FunctionReporter` parses a `do.call()` whose function argument is a string naming a non-syntactic function, such as `do.call("[<-", ...)`. (#335)
* `FunctionReporter` now determines exported functions from the package namespace's export metadata via `getNamespaceExports()` instead of listing the attached `package:<pkg>` environment. Previously, running pkgnet after `devtools::load_all()` marked every function as exported. (#347 Thanks @hughjonesd!)

# pkgnet 0.6.1
Expand Down
6 changes: 4 additions & 2 deletions R/FunctionReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ FunctionReporter <- R6::R6Class(

if (listable){

# If do.call and first argument is string (atomic), covert to call
# If do.call and first argument is string (atomic), convert to symbol.
# as.name() is used rather than parse() because the string can name a
# non-syntactic function such as "[<-", which is not parseable as text.
if (length(x) >= 2){
if (deparse(x[[1]])[1] == "do.call" & is.character(x[[2]])){
x[[2]] <- parse(text=x[[2]])
x[[2]] <- as.name(x[[2]])
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-FunctionReporter-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ test_that(".parse_function correctly handles next control statement", {
})
})

test_that(".parse_function resolves do.call function names given as strings", {
myfunc <- function() {
do.call("innerfunc1", list(innerfunc2()))
}
result <- pkgnet:::.parse_function(body(myfunc))
expect_true(all(c("innerfunc1", "innerfunc2") %in% result))
})

test_that(".parse_function handles do.call with a non-syntactic function name", {
myfunc <- function() {
do.call("[<-", list(x, 1, value = innerfunc1()))
}
result <- pkgnet:::.parse_function(body(myfunc))
expect_true("innerfunc1" %in% result)
})

test_that(".parse_R6_expression correctly parses expressions for symbols", {
# Correctly parses body of function and finds all function symbols
expect_true({
Expand Down
Loading