setPrompt {jamba} | R Documentation |
set R prompt with project name and R version
Description
set R prompt with project name and R version
Usage
setPrompt(
projectName = "unnamed",
useColor = TRUE,
projectColor = "yellow",
bracketColor = "white",
Rcolors = c("white", "white", "white"),
PIDcolor = NA,
promptColor = "white",
usePid = TRUE,
resetPrompt = FALSE,
addEscape = NULL,
updateOptions = TRUE,
debug = FALSE,
verbose = FALSE,
...
)
Arguments
projectName |
|
useColor |
|
projectColor , bracketColor , Rcolors , PIDcolor , promptColor |
|
usePid |
|
resetPrompt |
|
addEscape |
|
updateOptions |
|
debug |
|
verbose |
|
... |
additional parameters are passed to |
Details
This function sets a simple, colorized R prompt with useful information:
-
projectName
R version, major and minor included
Process ID (PID)
The prompt is defined in options("prompt")
.
Where Am I?
It is useful for the question: "What version of R?"
In rare cases, multiple R versions can be active at once (!), see
the rig
package for this exciting capability.
What Am I Doing?
The core question addressed is : "What am I working on?" The project name is especially useful when working with multiple active R sessions.
How Do I Stop This Thing?
It may also be useful for the question "How do I stop this thing", by returning the Process ID to be used to kill a long-running process without fear of killing the wrong long-running process.
Can It Have Color?
Then of course, meeting the above requirements, at least make it pretty.
Word-Wrap Gone Awry
A color-encoded prompt may sometimes interfere with word-wrapping on the R console. A long line may wrap prematurely before reaching the right edge of the screen. There are two frequent causes of this issue:
-
options("width")
is sometimes defined too narrow for the screen. When resizing the console, this option should be updated, and sometimes this update fails. To fix, either resize the window briefly again, or defineoptions("width")
manually. (Or debug the reason that this option is not being updated.) The terminal
locale
is sometimes mismatched with the terminal, usually caused by a layer of terminal emulation which is not compatible with ANSI color codes, or ANSI escape codes.Some examples: 'PuTTY' on 'Windows', GNU 'screen', 'tmux'.
Check
Sys.env("LC_ALL")
. The most common results are"C"
for generic C-type output, or a Unicode/UTF-8 locale such as"en_US.UTF-8"
('enUS' is English-USA in this context). In general, Unicode/UTF-8 is recommended, with benefit that it more readily displays other Unicode characters. However, sometimes the terminal environment (PuTTY or iTerm) is expecting one locale, but is receiving another. Either switching the terminal expected locale, or the R console locale, may resolve the mismatch.
R uses 'readline' for unix-like systems by default, and issues related to using color prompt are handled at that level.
The 'readline' library allows escaping ANSI color characters so they
do not contribute to the estimated line width, and these codes are
used in setPrompt()
.
The final workaround is useColor=FALSE
, but that would be a sad
outcome.
Value
list
named "prompt"
, suitable to use in options()
with the recommended prompt.
When updateOptions=FALSE
use: options(setPrompt("projectName"))
See Also
Other jam practical functions:
breakDensity()
,
call_fn_ellipsis()
,
checkLightMode()
,
check_pkg_installed()
,
colNum2excelName()
,
color_dither()
,
exp2signed()
,
getAxisLabel()
,
isFALSEV()
,
isTRUEV()
,
jargs()
,
kable_coloring()
,
lldf()
,
log2signed()
,
middle()
,
minorLogTicks()
,
newestFile()
,
printDebug()
,
reload_rmarkdown_cache()
,
renameColumn()
,
rmInfinite()
,
rmNA()
,
rmNAs()
,
rmNULL()
Examples
setPrompt("jamba")
setPrompt("jamba", projectColor="purple");
setPrompt("jamba", usePid=FALSE);
setPrompt(resetPrompt=TRUE);