编写 R lint 程序

发布于 2024-10-19 13:33:29 字数 379 浏览 2 评论 0 原文

当我用 python 编程时,我发现使用 pylint 非常有用。然而,当我用 R 编程时,没有什么可比的。

作为一个小型副项目,我认为尝试编写一个小型 lint 程序会很有趣。没什么太奇特的,大致如下:

  • 确保函数名称是驼峰式大小写
  • 平均函数长度
  • 检测未使用的变量
  • 间距。例如, function(x=1, y=2) 而不是 function(x=1,y=2)

但是,我不确定如何开始(我已经开始查看 pylint 源代码)。

我应该如何开始?是否有针对此类项目的标准编程技术?我应该考虑什么好的资源吗?

我想用 R 编写整个项目。

When I program in python, I find using pylint very useful. However, when I program in R, there is nothing comparable.

As a small side project, I thought it would be fun to try and write a small lint program. Nothing too fancy, something along the lines of:

  • Making sure function names are camel case
  • Average function length
  • Detecting unused variables
  • Spacing. For example, function(x=1, y=2) instead of function(x=1,y=2)

However, I'm unsure of how to get started (I have started to look through the pylint soure code).

How should I get started? Are there standard programming techniques for this type of project? Any good resources that I should consider?

I would like to write the entire project in R.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青春有你 2024-10-26 13:33:29

查看 R 附带的包 codetools。一些详细信息可以在 CRAN 页面。例如,当您执行 R CMD 检查时,包中的代码就会运行,因此可以捕获未使用的变量等。这可能会让您开始了解 rlint 的这方面。

为了回答其他一些方面......我开始编写执行一项任务的简单函数,例如将函数名称转换为驼峰式大小写。当您构建一个小函数体时,您可以将它们合并到一个工作的 lint 包装器函数中,同时允许用户/开发人员在不想要完整的 lint 行为时灵活地调用特定函数。

Take a look at package codetools that comes with R. Some details are found on the CRAN page for the package. The code in the package is run when you do R CMD check for example so can catch unused variables etc. That might get you started on that aspect of rlint.

To answer some of the other aspects... I'd start of writing simple functions that do one task, such as convert functions names to camel case. As you build up a body of small functions you can amalgamate them into a working lint wrapper function, whilst allowing users/developers flexibility to call the specific functions if they don't want the full lint behaviour.

留一抹残留的笑 2024-10-26 13:33:29

lintr 是一个 R 包,可以对样式和可能的语义错误进行代码检查。它在底层使用了代码工具,并在其顶部使用了额外的 linting。

它还与 Emacs、Vim、Sublime Text 和 RStudio 集成。

lintr is an R package that does code linting for both style and possible semantic errors. It uses codetools under the hood as well as additional linting on top of it.

It also integrates with Emacs, Vim, Sublime Text and RStudio.

寄意 2024-10-26 13:33:29

最近,有人为 R 提供了一个 lint 包:
http://cran.r-project.org/web/packages/lint/index.html< /a>

看起来它正处于早期开发阶段。它在 Github 上:
https://github.com/halpo/lint.git

Recently, someone put up a lint package for R:
http://cran.r-project.org/web/packages/lint/index.html

Looks like it's in early development. It's on Github here:
https://github.com/halpo/lint.git

痕至 2024-10-26 13:33:29

“R CMD 检查”程序可能会帮助您。它所做的一件事是找到似乎未初始化的变量。这通常是一个错字。该检查过程的代码可能会对您有所帮助。

我不认为这是一项小工作!

The "R CMD check" procedure might help you. One thing it does is find variables that are used without seeming to be initialised. This is often a typo. The code for that check procedure might help you.

I don't think its a small job though!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文