Set font and font size in R Console programmatically?
Asked Answered
K

2

6

Is it possible to set the console font and font size, as I would with "Edit->GUI preferences", programmatically? What would a function for this look like? I am on windows.

Knott answered 5/2, 2013 at 16:38 Comment(0)
S
11

On Windows (at least), the $R_HOME/etc/Rconsole config file sets many optional parameters for the console and pager. Here's the section that you could hand-edit to change the default font and font size:

## Font.
# Please use only fixed width font.
# If font=FixedFont the system fixed font is used; in this case
# points and style are ignored. If font begins with "TT ", only
# True Type fonts are searched for.
font = TT Courier New
points = 10
style = normal # Style can be normal, bold, italic

To change the values from the command line of an active R session, you could use the loadRconsole() function. It reads in a text file containing directives of the form shown above, which will overwrite the values read from Rconsole when R was launched. Here's an example:

temp <- tempfile()
cat("points = 13\n", file = temp)
cat("style = italic\n", file = temp, append = TRUE)
loadRconsole(file = temp)

## And then, to reset to the defaults:
loadRconsole(file = file.path(R.home(), "etc/Rconsole"))
Swagman answered 5/2, 2013 at 17:27 Comment(2)
Seems like cat is rewriting the tempfile, but with append=TRUE this works great. Thanks!Knott
@KarstenW. -- Yes, thanks. I forgot to add that when I cleaned it up for presentation. (I tested it with a single-line cat call.)Deplane
S
0

Hold control and scroll up with your wheel, just like a word doc or web page.

Sloop answered 16/10 at 18:19 Comment(1)
This could be a useful tip for RStudio users, but the OP asked how to do it programmatically (i.e. using R code)Expectant

© 2022 - 2024 — McMap. All rights reserved.