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

updated formatting in print.R6 (fixes #173) #174

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 8 additions & 1 deletion R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object_summaries <- function(x, exclude = NULL) {
"active binding"
} else {
obj <- .subset2(x, name)
if (is.function(obj)) deparse(args(obj))[[1L]]
if (is.function(obj)) "function"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to insert the end result here, instead of marking it as "function" and replacing later. This is because it keeps things simpler, and because it avoids the possibility of an error if a member is the string "function".

Something like:

     if (is.function(obj)) {
       txt <- deparse(args(obj), width.cutoff = 60L)
       txt <- txt[-length(txt)]  # Drop last line, which is "NULL"
       paste(txt, collapse = "\n")
     }

Note that the value I used for width is a bit arbitrary.

Ideally, it would wrap so that the total width (including indentation that is added later) is less than or equal to getOption('width'), but I think the way deparse uses width.cutoff is that it wraps after that number of characters.

# Plain environments (not envs with classes, like R6 or RefClass objects)
else if (is.environment(obj) && identical(class(obj), "environment")) "environment"
else if (is.null(obj)) "NULL"
Expand All @@ -122,6 +122,13 @@ object_summaries <- function(x, exclude = NULL) {
}
}, FUN.VALUE = character(1))

# Change functions from name to signature
for (i in which(values == 'function')){
obj_name <- obj_names[[i]]
sig <- deparse(args(.subset2(x, obj_name)))[[1L]]
obj_names[[i]] <- gsub("^function ", obj_name, sig)
}

paste0(obj_names, ": ", values, sep = "")
}

Expand Down