RStudio 如何确定控制台宽度,为什么它似乎总是出错? [英] How does RStudio determine the console width, and why does it seem to be getting it consistently wrong?

查看:52
本文介绍了RStudio 如何确定控制台宽度,为什么它似乎总是出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 RStudio 中发现了 wid <- options()$width,它似乎是我日常控制台使用中非常恼火的源头(或者更接近源头).我应该事先声明,我目前使用的是 R 3.2.2、RStudio 0.99.491、Linux Mint 17.3(基于 Ubuntu 14.04.3 LTS)

据我所知,wid 应该用字符来衡量——如果 wid 等于 52,那么一个人应该能够适应屏幕两次(考虑到固定宽度的默认字体),但情况似乎并非如此:

如您所见,尽管 wid 等于 52,但我无法适应字母表两次 -- 我想出了 6 个字符.我还注意到,这意味着它不是仅仅是因为命令提示符箭头和空格(>)的存在.

这个问题似乎有点成正比——如果我的 wid 达到 78,我只能容纳 70 个字符;高达 104、93,所以 wid 的折扣相当一致(旁注:这也表明我的假设 wid 以字符衡量可能是正确的).>

由此产生的问题是控制台输出经常超出预期的行数,使输出变得丑陋且难以消化;举个例子,简单的剪断 setDT(lapply(1:30, function(x) 1:3))[] 为我生成:

我似乎很清楚,输出是在实践中不可用的屏幕宽度上尝试的——在内部,比实际存在的屏幕宽度更大的屏幕宽度用于打印.

这给我留下了三个问题:

  1. options()$width 是如何确定的?
  2. 为什么总是错误?
  3. 我们可以做些什么来覆盖这个错误?

解决方案

找到了一个 在 Rstudio 支持上发布有关此内容 似乎问题与高 DPI 显示器有关;RStudio 0.99.878 版(今天刚刚发布!幸运的话),根据发行说明:><块引用>

错误修复

...

  • 在高 DPI 显示器上正确计算 getOption(width")

希望这可以帮助其他遇到此问题的人!我很想在 /r/oddlysatisfying B-)

上发帖

希望在 RStudio GitHub 页面上看到相关提交,如果有人可以找到它(我运气不好).

I just discovered wid <- options()$width in RStudio, and it seems to be the source (or rather, much closer to the source) of much irritation in my everyday console usage. I should say up front that I'm currently on R 3.2.2, RStudio 0.99.491, on Linux Mint 17.3 (built over Ubuntu 14.04.3 LTS)

As I understand it, wid should be measured in characters -- if wid is equal to 52, say, then one should be able to fit the alphabet on the screen twice (given the fixed-width default font), but this doesn't appear to be the case:

As you can see, despite having wid equal to 52, I am unable to fit the alphabet twice -- I come up 6 characters short. I also note that this means it is not simply due to the presence of the command prompt arrow and space (> ).

The problem seems somewhat proportional -- if I have wid up to 78, I can only fit 70 characters; up to 104, 93, so wid is about 88% off pretty consistently (side note: this also suggests my assumption wid is measured in characters is probably right).

The problem that this engenders is that oftentimes console output overflows beyond its intended line, making the output ugly and hard to digest; take, for example, the simple snipped setDT(lapply(1:30, function(x) 1:3))[] which produces for me:

It seems clear to me that the output was attempted on a screen width which was not available in practice -- that internally, a larger screen width than actually exists was used for printing.

This leaves me with three questions:

  1. How is options()$width determined?
  2. Why is it so consistently wrong?
  3. What can we do to override this error?

解决方案

Found a post about this on Rstudio support and it seems the issue has to do with high DPI Displays; there is a claimed bug fix in RStudio version 0.99.878 (released just today! as luck would have it), according to the release notes:

Bug Fixes

...

  • Correct computation of getOption("width") on high DPI displays

Hope this helps anyone else experiencing this! I'm tempted to post about this on /r/oddlysatisfying B-)

Would love to see the relevant commit on the RStudio GitHub page if anyone can track it down (I had no luck).

这篇关于RStudio 如何确定控制台宽度,为什么它似乎总是出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆