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

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

wants to merge 1 commit into from

Conversation

jameslamb
Copy link

@wch On #171 , you recommended I look at #173 .

Please consider this PR that I think addresses it.

An example:

thing <- R6::R6Class(
    classname = "thing",
    public = list(
        some_func = function(x = TRUE){NULL}
        , x = 5
    )
)
print(thing)

@jameslamb
Copy link
Author

@wch Friendly reminder about this small PR

@@ -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.

@jameslamb
Copy link
Author

I am going to close this. Someone else can pick up the issue.

@jameslamb jameslamb closed this Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants