-
Notifications
You must be signed in to change notification settings - Fork 57
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
Print methods and the environment pane for R6 instances #217
Comments
This is how to create a print method: https://r6.r-lib.org/articles/Introduction.html#printing-r6-objects-to-the-screen For str.foo <- function(object, ...) {
...
} |
I figured I would be able to avoid creating a print method if I wrote format methods. Shouldn't that work since format is what is called by |
That works as well: foo <- R6::R6Class("foo",
public = list(
format = function(...) "foobar"
)
)
foo$new()
#> foobar Created on 2020-10-21 by the reprex package (v0.3.0) |
Right. But I am not interested in changing how |
I might be missing something, but can't you just create a format method for your class that formats its members differently? |
For sure. That's my fallback plan. Just create a new |
Alright after looking over |
For posterity, I think the issue I was facing was beyond my control. In particular, one expects that RStudio uses So this is why I couldn't get my |
Hi @wch,
I just have a couple (probably) simple questions about the
R6
print method and also how to modify how anR6
object is displayed in theEnvironment
pane in RStudio.For the first part, if I didn't feel like designing a whole custom
print
method for myR6
class, is there a way to modify how apublic
method or field is presented?I see that
print.R6
is:So for example, the default way an
array
is presented is:But I would like to customize it to show the dimensions, so I thought a new
S3
method forformat
would work, but it doesn't. Movingformat.array
to the global environment didn't help either.Can this be achieved without defining a custom print method (such as by writing a new
S3
method forformat
)?Second, it's my understanding that RStudio uses
str()
S3 methods to present objects in theEnvironment
pane. But no matter what I've tried I can't seem to get myR6
object to show up differently in the pane. Is this possible? If so, any suggestions on how to achieve this?The text was updated successfully, but these errors were encountered: