使用包“设置"设置和重置 R 选项中的 scipen 和数字 [英] Setting and resetting scipen and digits in R options with package `settings`

查看:109
本文介绍了使用包“设置"设置和重置 R 选项中的 scipen 和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 R 中设置 options 在想要避免使用科学记数法时很有用.options(scipen = 100,digits = 4) 是一种可能性.

Setting options in R can be useful when wanting to avoid scientific notation. options(scipen = 100, digits = 4) is one possibility.

似乎在 R Studio 中的每个 R 会话开始时都需要重新运行此命令.

It seems that at the start of every R session in R Studio this command needs to be re-run.

我正在寻找一种方法来重置所有 R options 一旦它们被设置并找到了这篇文章:如何将所有 options() 参数重置为其默认值?

I was searching for a way to reset all R options once they have been set and found this post: How do I reset all options() arguments to their default values?

一旦 options 已经设置,实际的答案就会迟到".包 settings 提供了一种重置 R 中所有选项的方法.但是,这似乎不适用于 scipendigits(参见示例).

The actual answer comes 'to late' once the options have been set already. The package settings offers a way to reset all options in R. This does not seem to work for scipen and digits however (see example).

示例:

require(settings)
#> Loading required package: settings

1/987654
#> [1] 1.0125e-06

options(scipen = 100, digits = 4)

1/987654
#> [1] 0.000001013

settings::reset(options)

1/987654
#> [1] 0.000001013

reprex 包 (v0.2.1) 于 2018 年 12 月 21 日创建

Created on 2018-12-21 by the reprex package (v0.2.1)

问题:

  1. 是否还有其他可能将 scipendigits 重置为它们的标准值?
  2. 什么是标准值?
  1. Is there any other possibility to reset both scipen and digits to their standard values?
  2. What are the standard values?

谢谢

推荐答案

好吧,暂时解决你的问题:默认是 options(scipen=0,digits=7)

Well, to solve your problem for now: the defaults are options(scipen=0, digits=7)

但总的来说,我认为 R 的工作方式是在启动时设置选项,并且默认值不会显式存储在任何地方.此外,如果您在配置文件(例如 .Rprofile.

But generally, I think the way R works is that options are set at startup, and the defaults are not stored anywhere explicitly. Also, the notion of a "default" may be fuzzy, if you set options in configuration files such as .Rprofile.

所以我认为重置所有选项最有用的方法是简单的重启.如果你想保留你的数据,你可以使用 save.image().大多数情况下,我发现重新启动通常会使我的代码更具可重现性.

So I think the most useful way to reset all options is a simple restart. If you want to keep your data you can use save.image(). And mostly, I found that restarting often made my code much more reproducible.

这篇关于使用包“设置"设置和重置 R 选项中的 scipen 和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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