美文网首页
R包代码格式化

R包代码格式化

作者: 见龙在田007er2770 | 来源:发表于2020-05-08 08:58 被阅读0次

为了开发R包,写出漂亮、规范的R代码,需要一些代码检查、格式化的工具。

1. styler

styler allows you to format .R files, packages or entire R source trees according to a style guide. The following functions can be used for styling:

style_text() to style a character vector.

style_file() to style a single .R file.

style_dir() to style all .R files in a directory.

style_pkg() to style the source files of an R package.

styler_addins (RStudio Addins) to style either selected code or the active file.
这个包还是一个Rstudio的插件(Addins),直接点击二级菜单里的 Styler选项就能对R代码格式化,包括对齐、= 变 <- 等。

2. formatR

The formatR package was designed to reformat R code to improve readability; the main workhorse is the function tidy_source(). Features include:

long lines of code and comments are reorganized into appropriately shorter ones
spaces and indent are added where necessary
comments are preserved in most cases
the number of spaces to indent the code (i.e. tab width) can be specified (default is 4)
an else statement in a separate line without the leading } will be moved one line back
= as an assignment operator can be replaced with <-
the left brace { can be moved to a new line
这是谢益辉老大的包(https://yihui.name/formatR/),竟然还用 shiny 做了个图形界面。

3. lintr

lintr is an R package offering static code analysis for R. It checks adherence to a given style, syntax errors and possible semantic issues, see the animation below. In this README find out

what linters i.e. checks are supported;

how to configure the project to e.g. tweak checks and ignore files;

how to setup lintr for on-the-fly checking in different editors;

how to use lintr in combination with continuous integration;
这个包是静态的检查,不能像上面两个包对不规范的地方进行更改,但是可以检查出更多的错误。而且此工具除了支持Rstudio,还支持多个代码编辑器,例如Emacs、Sublime Text 3、Vim、Atom,牛逼坏了。更为详细内容查看 https://github.com/jimhester/lintr

原文链接

相关文章

  • R包开发之代码格式化

    为了开发R包,写出漂亮、规范的R代码,需要一些代码检查、格式化的工具。 1. styler styler allo...

  • R包代码格式化

    为了开发R包,写出漂亮、规范的R代码,需要一些代码检查、格式化的工具。 1. styler styler allo...

  • R语言扩展包xlsx() (02)修改单元格底色

    xlsx()包,是可以让R读、写、格式化xlsx文件的扩展包(接上篇)。 3.修改单元格底色。 先给出代码: 代码...

  • 【Java基础】IntelliJ IDEA常用快捷键

    格式化代码: Ctrl + Alt + L 代码右移:Tab键 代码左移:Shift + Tab键 自动导包:Al...

  • 学习小组Day6笔记——R包

    R包的使用 利用代码安装与加载R包 镜像设置 安装:install.package("包") 加载:library...

  • Day6R包学习-谢大飞

    学习R包 包是 R 函数、实例数据、预编译代码的集合,包括 R 程序,注释文档、实例、测试数据等。R 语言相关的包...

  • goimpots 安装

    gofmt 保存的时候自动 格式化go代码goimports 保存的时候自动导入处理包,以及自动格式化 用来替代 ...

  • R语言扩展包xlsx() (01)

    xlsx()包,是一个可以让R读、写、格式化xlsx文件的扩展包。 为什么不用相对有更多教程的RODBC包? 最重...

  • R语言学习记录

    R、Rstudio安装 包的安装 r语言实战相关代码记录 报错系列

  • 2018-10-31

    Android Studio使用技巧 常用快捷键 搜索和替换:ctrl+R ,Replace 代码格式化:ctr...

网友评论

      本文标题:R包代码格式化

      本文链接:https://www.haomeiwen.com/subject/rdjxnhtx.html