【问题标题】:Set font and font size in R Console programmatically?以编程方式在 R 控制台中设置字体和字体大小?
【发布时间】:2013-01-20 16:00:53
【问题描述】:

是否可以设置console font and font size,就像使用“编辑->GUI 首选项”,以编程方式?这个函数的外观如何?我在窗户上。

【问题讨论】:

    标签: windows r user-interface console


    【解决方案1】:

    在 Windows 上(至少),$R_HOME/etc/Rconsole 配置文件为控制台和寻呼机设置了许多可选参数。这是您可以手动编辑以更改默认字体和字体大小的部分:

    ## 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
    

    要从活动 R 会话的命令行更改值,您可以使用 loadRconsole() 函数。它读入一个包含上述形式指令的文本文件,这将覆盖在 R 启动时从Rconsole 读取的值。这是一个例子:

    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"))
    

    【讨论】:

    • 似乎cat 正在重写临时文件,但使用append=TRUE 效果很好。谢谢!
    • @KarstenW。 - 对了谢谢。当我清理它以进行演示时,我忘记添加了。 (我用单行的 cat 调用对其进行了测试。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2016-03-02
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多