r-在tidyverse的styler包中,style_text在第一次运行时提示用户输入


> packageVersion('styler')
[1] ‘1.3.2’
> style_text("A <- 1")
The R.cache package needs to create a directory that will hold cache files. It is convenient to use  ‘C:UsersA0765618AppDataLocalRR.cache’ because it follows the standard on your operating system and it remains also after restarting R. Do you wish to create the 'C:UsersA0765618AppDataLocalRR.cache' directory? If not, a temporary directory (C:UsersA0765618AppDataLocalTempRtmp6z4Eit/.Rcache) that is specific to this R session will be used. [Y/n]: 

如果没有这个提示,我如何在一开始就运行这个功能?我可以在打电话前根据提示设置答案吗?例如,如何将其设置为n,以便不需要提示?

这个函数将在一个闪亮的应用程序中调用,因此控制台中出现的这个提示将导致错误。

TLDR

在调用目录应该已经存在的{styler}之前将其放在:

options(R.cache.rootPath = '/path/to/your/cache/dir')

您有以下选项:

完全停用缓存

首先,您可以通过使用styler::cache_deactivate()完全停用缓存来解决缓存问题。然后,提示不应该出现。要使其永久化,请将这一行放在.Rprofile中。

以编程方式设置缓存

但是,如果您想从缓存带来的设置速度中获益,可以通过编程方式进行设置。我只是在更新它的文档(如果你有意见,请告诉我(:

在某些情况下,您希望避免上述交互式提示。在这种情况下,在调用{styler}API之前,可以使用R选项R.cache.rootPath或环境变量R_CACHE_ROOTPATH将缓存的路径设置为现有路径。这应该避免出现提示。R.cache::setCacheRootPath("/path/to/cache")也是可编程的,但如果以交互方式调用,可能无论如何都会给出提示。

所以只执行options(R.cache.rootPath = '/path/to/your/cache/dir')

您也可以通过设置选项styler.colored_print.vertical来静音漂亮的颜色警告(如果您不想安装它(,如help(print.vertical, package = 'styler')所述。

此外,styler > 1.3.2中有一个styler.quiet选项,但它可能不会产生任何影响,因为您看到的内容直接来自{R.cache}

R.cache::setCacheRootPath(getwd())

确实会产生不希望的信息和提示:

The R.cache package needs to create a directory that will hold cache files. It is
convenient to use  '<xxxx>/Caches/R/R.cache' because it follows the standard on your
operating system and it remains also after restarting R. Do you wish to create the
'<xxxx>/Caches/R/R.cache' directory? If not, a temporary directory (/var/folder
/47/4_fn5xyx01b8_8bnyn8cpv3c0000gn/T//RtmpdO3NGa/.Rcache) that is specific to this
R session will be used. [Y/n]:

但是,根据提示中的提示,

R.cache::setCacheRootPath("<xxxx>/Caches/R/R.cache")

在没有错误或警告的情况下运行。

然后,在安装prettycode包之后,

style_text("A <- 1")

产生

A <- 1

没有消息或警告。

值得给tidyverse留言要求styler.silent选项吗?

最新更新