在生产中运行的 R 脚本的最佳实践编码 [英] Best Practise Coding for R script running in production

查看:52
本文介绍了在生产中运行的 R 脚本的最佳实践编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 linux 生产服务器和一些我们正在编写的脚本,我们希望在它上面运行以收集数据,然后将这些数据放入 Spark 数据湖中.

We have a linux production server and a number of scripts we are writing that we want to run on it to collect data which then will be put into a Spark data lake.

我的背景是 SQL Server/Fortran,并且有非常具体的最佳实践需要遵循.

My background is SQL Server / Fortran and there are very specific best practices that should be followed.

  • 生产环境在版本控制方面应该是稳定的,无论是从代码的角度,还是安装的应用程序、操作系统等.
  • 对代码/应用程序/操作系统的更改应在单独的环境中或以受控且可以撤消的方式进行.
  • 如果存在第二个环境,则可以并行执行以测试系统更改.
  • (在很大程度上),开发人员被限制更改生产环境

在审查 R 代码时,我有很多问题.

In reviewing the R code, there are a number of things that I have questions on.

  • library(), install.packages() - 我想排除每次运行脚本时安装更新版本包的可能性?
  • 如何最好地调用通过 CRON 作业调度的 R 包?这里有很多选择.
  • 在使用 RSelenium 时,使用 gui/Web 浏览器或虚拟化 Web 浏览器的最有效方法是什么?

推荐答案

在任何情况下,我都会取消自动更新包的任何概念.期望您依赖的包的维护者引入向后不兼容的更改.如果您自动更新,您的代码将突然停止工作.不要假设任何神圣的东西.

In any case I would scratch any notion of updating the packages automatically. Expect the maintainers of the packages you rely on to introduce backward incompatible changes. Your code will stop working out of the blue if you auto update. Do not assume anything sacred.

过去,您需要问问自己您的部署需要多少实践.如果您可以手动设置每个部署,那么您可能可以使用 packrat 包来下拉并保留您正在使用的确切版本的源代码.这种方式重现您的部署是痛苦的,但至少是可能的.如果您想要完全自动化的可重复部署,我建议您开始使用您的包构建 docker 镜像,并用日期或版本标记它们.

Past that you need to ask yourself how much hands on is your deployment. If you're OK with manually setting up each deployment then you can probably get away using the packrat package to pull down and keep sources of the exact versions you are using. This way reproducing your deployment is painful, but at least possible. If you want fully automated reproducible deployments I suggest you start building docker images with your packages and tagging them with dates or versions.

如果你没有为重现你的环境做任何准备,你就是在自找麻烦,虽然一开始简单地修复任何不兼容的问题似乎没有问题,因为它们提出了更新,并且确实似乎是来自权力的官方工作流程不管那是多么误导;最终,随着您的代码库的增长,您最终要做的就是这些.

If you make no provisions for reproducing your environment you are asking for trouble, while it may seem OK at first to simply fix any incompatibilities as they come up with updates, and does indeed seem to be the official workflow from the powers that be, however misguided that is; eventually as your codebase grows that will be all you will end up doing.

这篇关于在生产中运行的 R 脚本的最佳实践编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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