Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reading active bindings when printing #38

Merged
merged 2 commits into from Jan 6, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Avoid reading active bindings when printing

  • Loading branch information...
oscardelama committed Jan 5, 2015
commit c94c7ddc5507ba40bc90da7eedf06f0813d06be9
@@ -70,12 +70,14 @@ object_summaries <- function(x) {
obj_names <- ls(x, all.names = TRUE)

values <- vapply(obj_names, function(name) {
obj <- x[[name]]
if (is.environment(x) && bindingIsActive(name, x)) "active binding"

This comment has been minimized.

Copy link
@wch

wch Jan 6, 2015

Member

I'd prefer that this has a style like:

if (is.environment(x) && bindingIsActive(name, x)) {
  "active binding"
} else {
  ...
}
else if (is.function(obj)) "function"
else if (is.environment(obj)) "environment"
else if (is.atomic(obj)) trim(paste(as.character(obj), collapse = " "))
else paste(class(obj), collapse = ", ")
else {
obj <- x[[name]]
if (is.function(obj)) "function"
else if (is.environment(obj)) "environment"
else if (is.atomic(obj)) trim(paste(as.character(obj), collapse = " "))
else paste(class(obj), collapse = ", ")
}
}, FUN.VALUE = character(1))

paste0(
@@ -112,6 +112,18 @@ test_that("Active bindings work", {
x2 = function(value) {
if (missing(value)) return(self$x * 2)
else self$x <- value/2
},

sqrt_of_x = function(value) {
if (!missing(value))
# In "setter" role
stop("Sorry this is a read-only variable.")
else {
# In "getter" role
if (x < 0) stop("The requested value is not available.")

This comment has been minimized.

Copy link
@wch

wch Jan 6, 2015

Member

Should these be self$x?

else sqrt(x)
}

}
)
)
@@ -123,6 +135,13 @@ test_that("Active bindings work", {
A$x2 <- 60
expect_identical(A$x2, 60)
expect_identical(A$x, 30)

A$x <- -2
expect_error(A$sqrt_of_x)
# print does not throw an error trying to read
# the active binding variables
muted_print <- function(x) capture.output(print(x))
expect_that(muted_print(A), not(throws_error()))
})


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.