-
Notifications
You must be signed in to change notification settings - Fork 70
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 width is not recognized at R session startup #578
Comments
Yes, I am afraid that this is because RStudio hasn't set the console width yet, when the profile runs, so there isn't much we can do here. If you feel strongly about this, you can look at the rstudio/rstudio repository. It is possible that there is an issue about this already, and if not then you can open one, although I suspect that they cannot fix it at this point. |
For there record, it seems like there is no |
Thanks for the quick reply! I think I have just figured it out with: # .Rprofile
local({
c_args <- commandArgs()
likely_rstudio <- basename(c_args[1L]) == "RStudio"
if (isTRUE(likely_rstudio)) {
setHook("rstudio.sessionInit", function(newSession) {
if (newSession) {
print(cli::console_width())
}
}, action = "append")
} else {
print(cli::console_width())
}
}) Maybe you can implement something of that sort into {cli}, but I'm not sure of the consequences. Nonetheless, I think for my purpose it'll suffice. |
So what does this code do? |
Oh, I'm sorry. First I get CLI arguments that were supplied when the R session was invoked (as c_args <- commandArgs()
likely_rstudio <- basename(c_args[1L]) == "RStudio"
In case I think that RStudio invoked my R session, I can set up a hook described at https://docs.posit.co/ide/server-pro/rstudio_pro_sessions/session_startup_scripts.html or https://docs.posit.co/ide/server-pro/rstudio_pro_sessions/session_startup_scripts.html. So The point is to "wait" for RStudio to set up and then try to get the console width when it is likely we are dealing with RStudio. |
FWIW, if you are already using cli, you can call |
I am having a similar issue. I think this issue can be closed in cli however, unless there are plans to make However, there could be a bullet added in the cli documentation about this. |
Where? |
I had nothing particular in mind. I just meant that unless cli wants to hack its way into figuring out the console width on startup, then the issue could be closed. Doc suggestion: |
I want to print a nice welcome message at the RStudio project startup and I noticed that in the very first phases of an R session startup, it behaves as if the console is 80 characters wide. Note that it may be in fact the correct value and RStudio is only sluggish to set the console properties so they match what we see in the console pane.
Set this as your
.Rprofile
and restart the session:Notice you get 80 no matter what in the first case. The second one is run only after the RStudio is fully available.
Glad to hear anyone else's opinion!
EDIT: Now I noticed in the
cli
source that 80 is the fallback value. Maybe this whole mission is not possible.The text was updated successfully, but these errors were encountered: