哪些R函数不适合编程使用? [英] Which R functions are not suitable for programmatic use?

查看:71
本文介绍了哪些R函数不适合编程使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

browser这样的某些功能只有在交互使用时才有意义.

Some functions like browser only make sense when used interactively.

人们普遍认为subset函数只能交互使用.

类似地,sapply不适用于程序设计,因为它不能简化零长度输入的结果.

Similarly, sapply isn't good for programmatic use since it doesn't simplify the result for zero length inputs.

我正在尝试列出仅不适合编程使用的功能的详尽列表.

I'm trying to make an exhaustive list of functions that are only not suitable for programmatic use.

计划是要制作一个用于程序包检查的工具,以查看是否调用了这些函数并给出警告.

The plan is to make a tool for package checking to see if any of these functions are called and give a warning.

还有其他一些功能,例如file.choosereadline需要交互性,但是可以将它们包含在程序包中,因为最终用途将是交互性的.对于这个用例,我不太在乎这些,但可以随时将它们添加到列表中.

There are other functions like file.choose and readline that require interactivity, but these are OK to include in packages, since the end use will be interactive. I don't care too much about these for this use case but feel free to add them to the list.

我错过了哪些功能?

推荐答案

(随时进行编辑.)

以下函数应谨慎处理(这不一定意味着它们不适合编程):

The following functions should be handled with care (which does not necessarily mean they are not suitable for programming):

  • 根据输入不同,其输出的输出类别不一致的函数:sapplymapply(默认情况下)

内部行为取决于输入长度的函数:sampleseq

Functions whose internal behavior is different depending on the input length: sample, seq

在环境中评估其某些参数的函数:$subsetwithwithintransform.

Functions that evaluate some of their arguments within environments: $, subset, with, within, transform.

违反正常环境使用的功能:attachdetachassign<<-

Functions that go against normal environment usage: attach, detach, assign, <<-

允许部分匹配的功能:$

Functions that allow partial matching: $

仅在交互使用中有意义的功能:browserrecoverdebugdebugonceeditfixmenuselect.list

Functions that only make sense in interactive usage: browser, recover, debug, debugonce, edit, fix, menu, select.list

如果与以下用户输入配合使用,可能会构成威胁(病毒):,eval(parse(text=...))system.

Functions that can be a threat (virus) if used with user inputs: source, eval(parse(text=...)), system.

在某种程度上,每个生成警告而不是错误的函数.我建议使用options(warn = 2)将所有警告转换为编程应用程序中的错误.然后可以通过suppressWarningstry允许特定情况.

Also, to some extent, every function that generates warnings rather than errors. I recommend using options(warn = 2) to turn all warnings into errors in a programming application. Specific cases can then be allowed via suppressWarnings or try.

这篇关于哪些R函数不适合编程使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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