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

Custom print method for rco output #70

Open
ColinFay opened this issue Oct 4, 2019 · 3 comments
Open

Custom print method for rco output #70

ColinFay opened this issue Oct 4, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@ColinFay
Copy link

ColinFay commented Oct 4, 2019

Woud be nice to have a custom print method:

Current:

code <- paste(
  "code_to_optimize <- 8 ^ 8 * 1918",
  "cto <- code_to_optimize * 2",
  sep = "\n"
)
res <- optimize_text(code)
res
[1] "code_to_optimize <- 32178700288\ncto <- 64357400576"

Could be improved with:

code <- paste(
  "code_to_optimize <- 8 ^ 8 * 1918",
  "cto <- code_to_optimize * 2",
  sep = "\n"
)
res <- optimize_text(code)
class(res) <- c("rco.output", class(res))
print.rco.output <- function(x, ...){
  cat(x)
}
res
code_to_optimize <- 32178700288
cto <- 64357400576

# Or maybe
print.rco.output <- function(x, ...){
  cli::cat_rule("Optimized code:")
  cat(x)
}
res
── Optimized code: ─────────────────────────────────────
code_to_optimize <- 32178700288
cto <- 64357400576

Can also PR that :)

@jcrodriguez1989
Copy link
Owner

Hi @ColinFay ,
thank you very much for these two issues :D
I will be working on #69 as it needs documentation, testing, etc.
However, I would really appreciate if you could PR this one :)
thanks!

@ColinFay
Copy link
Author

ColinFay commented Oct 4, 2019

Nice.

So as suggested in #69, no cli::cat_rule as it's not from base?

@jcrodriguez1989
Copy link
Owner

Exactly, I would rather prefer the first option (no cli::).
Also, I could not find the code styling for class names. As far as I remember, the correct name for rco output would be RcoOutput, but I don't remember, so I would adhere to what you think.

@jcrodriguez1989 jcrodriguez1989 added the enhancement New feature or request label Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants