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

Console output questions #1238

Closed
2 tasks done
januz opened this issue Apr 9, 2020 · 7 comments
Closed
2 tasks done

Console output questions #1238

januz opened this issue Apr 9, 2020 · 7 comments

Comments

@januz
Copy link

januz commented Apr 9, 2020

Prework

  • Read and abide by drake's code of conduct.
  • Search for duplicates among the existing issues, both open and closed.
  • [] If you think your question has a quick and definite answer, consider posting to Stack Overflow under the drake-r-package tag. (If you anticipate extended follow-up and discussion, you are already in the right place!)

Questions

  1. Can one turn off the tips that get randomly displayed when loading drake. My package has drake listed under Depends: and I don't want users to see the tips mixed into my startup message.
  2. What determines how drake output is formatted (i.e., whether it is displayed with or without symbols like the triangle or X)?
@wlandau
Copy link
Member

wlandau commented Apr 9, 2020

  1. No, there is no such option. But the message should only be called when the entire package is loaded, so if you put drake in Imports: instead, that should take care of it. Imports: is almost always preferred instead of Depends: anyway, with @importFrom calls in your roxygen2 docstrings to import only specific functions.
  2. The cli package generates those symbols you see, and here is where drake generates them.

drake/R/logger.R

Lines 110 to 164 in 85ea21f

target_msg <- function(target) {
if (.pkg_envir$has_cli) {
UseMethod("target_msg")
} else {
message(paste(class(target), target)) # nocov
}
}
target_msg.finalize <- function(target) {
symbol <- cli::col_green(cli::symbol$stop)
msg <- paste(symbol, "finalize", target)
message(msg)
}
target_msg.cancel <- function(target) {
symbol <- cli::col_yellow(cli::symbol$stop)
msg <- paste(symbol, "cancel", target)
message(msg)
}
target_msg.dynamic <- function(target) {
symbol <- cli::col_green(cli::symbol$play)
msg <- paste(symbol, "dynamic", target)
message(msg)
}
target_msg.fail <- function(target) {
symbol <- cli::col_red(cli::symbol$cross)
msg <- paste(symbol, "fail", target)
message(msg)
}
target_msg.recover <- function(target) {
symbol <- cli::col_green(cli::symbol$tick)
msg <- paste(symbol, "recover", target)
message(msg)
}
target_msg.retry <- function(target) {
symbol <- cli::col_yellow(cli::symbol$warning)
msg <- paste(symbol, "retry", target)
message(msg)
}
target_msg.subtarget <- function(target) {
symbol <- cli::col_green(cli::symbol$pointer)
msg <- paste(symbol, "subtarget", target)
message(msg)
}
target_msg.target <- function(target) {
symbol <- cli::col_green(cli::symbol$play)
msg <- paste(symbol, "target", target)
message(msg)
}
.

There is a different symbol for each of the following cases.

  • Start an ordinary target.
  • Start a dynamic target.
  • Start a dynamic sub-target.
  • Finalize a dynamic target.
  • Cancel a target.
  • Observe a target failure.
  • �Retry a failed target.
  • Recover an old target instead of building it from scratch.

@wlandau wlandau closed this as completed Apr 9, 2020
@januz
Copy link
Author

januz commented Apr 9, 2020

Thank you for the info, @wlandau!

Re 1) I am using Depends: to load the whole drake package. The reason is that I want to make it as easy as possible for a user to use the research compendium, i.e., they just have to load my R package and then can use

a) the package's functions to copy the analysis directory structure and check/reproduce the analysis (I explicitly call drake functions using the :: syntax in those functions), BUT ALSO

b) standard drake functions like vis_drake_graph, loadd(), etc. to explore the analysis.

As far as I understand, I cannot achieve that with using @import/@importFrom, or can I? So it would be great if one could configure drake not to show any tips. But I see that my use case is probably not a very common one :)

@wlandau
Copy link
Member

wlandau commented Apr 10, 2020

You might be able to go with Imports: and then sneak a suppressPackgeStartupMessages(library(drake)) call inside a custom .onAttach() function in your package. Not recommended for a reusable infrastructure tool, but it might solve your problem for research compendia.

@januz
Copy link
Author

januz commented Apr 12, 2020

Thank you, @wlandau. That'll do it.

@januz
Copy link
Author

januz commented Jun 26, 2020

Sorry to bring this issue up again, @wlandau. I rewrote my package to include wrapper functions that explicitly call drake functions so that I don't have to load the whole package at all. But there's one more thing that still bothers me:

I have a function that calls drake::make() to execute the analysis pipeline. Randomly, when I call this function, I get the tip to use drake::r_make() instead. I'm worried that it might be confusing to users of my research compendia to get a message that they could increase the reproducibility by using r_make() as the whole point of providing my analysis as a research compendium / R package is for it to be reproducible (the function that calls drake::make() is even called reproduce_analysis()).

Would you consider adding an option to turn off the r_make() tip? Or could the tip maybe only be shown if the make() is not called from within a function?

@wlandau
Copy link
Member

wlandau commented Jun 26, 2020

Implemented just now in 9267a83. The message should no longer appear if you set getOption("drake_r_make_message") to FALSE.

@januz
Copy link
Author

januz commented Jun 26, 2020

Great, thank you so much, @wlandau!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants