如何组织大型 R 程序? [英] How to organize large R programs?

查看:21
本文介绍了如何组织大型 R 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我承担任何复杂的 R 项目时,我的脚本很快就会变得冗长和混乱.

When I undertake an R project of any complexity, my scripts quickly get long and confusing.

我可以采用哪些实践来使我的代码始终令人愉快地工作?我正在考虑类似的事情

What are some practices I can adopt so that my code will always be a pleasure to work with? I'm thinking about things like

  • 在源文件中放置函数
  • 何时将某些内容拆分到另一个源文件中
  • 主文件中应该包含什么
  • 将函数用作组织单位(考虑到 R 使得访问全局状态变得困难,这是否值得)
  • 缩进/换行的做法.
    • 对待(像 {?
    • 将 )} 之类的内容放在 1 行或 2 行上?

    基本上,您组织大型 R 脚本的经验法则是什么?

    Basically, what are your rules of thumb for organizing large R scripts?

    推荐答案

    标准答案是使用包 -- 参见 Writing R Extensions 手册以及网络上的不同教程.

    The standard answer is to use packages -- see the Writing R Extensions manual as well as different tutorials on the web.

    它给你

    • 一种按主题组织代码的准自动方式
    • 强烈建议您编写帮助文件,让您考虑界面
    • 通过 R CMD check
    • 进行了大量的健全性检查
    • 有机会添加回归测试
    • 以及命名空间的一种方式.

    在代码上运行 source() 适用于非常短的片段.其他所有内容都应该在一个包中——即使您不打算发布它,因为您可以为内部存储库编写内部包.

    Just running source() over code works for really short snippets. Everything else should be in a package -- even if you do not plan to publish it as you can write internal packages for internal repositories.

    至于如何编辑"部分,R Internals 手册在第 6 节中有出色的 R 编码标准.否则,我倾向于在 Emacs 的 ESS 模式.

    As for the 'how to edit' part, the R Internals manual has excellent R coding standards in Section 6. Otherwise, I tend to use defaults in Emacs' ESS mode.

    2008 年 8 月 13 日更新: David Smith 刚刚发布了关于 的博客谷歌 R 风格指南.

    Update 2008-Aug-13: David Smith just blogged about the Google R Style Guide.

    这篇关于如何组织大型 R 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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