Skip to content

Conversation

@HyukjinKwon
Copy link
Member

@HyukjinKwon HyukjinKwon commented Apr 9, 2017

This PR proposes to document R code styles. The contents are basically based on SPARK-6813.

2017-04-09 11 53 13

@HyukjinKwon
Copy link
Member Author

HyukjinKwon commented Apr 9, 2017

cc @srowen, @shivaram and @felixcheung, I remember I suggested this in apache/spark#14705 (comment) and I assume we want this.

The contents are based on SPARK-6813. It seems the current lintr emits an error for dot in variable names as observed before - apache/spark#17178 (comment)

This seems actually against https://google.github.io/styleguide/Rguide.xml#identifiers. I am going to submit a PR to disable multiple_dots_linter which I believe causes the error after this gets merged.

@JohnGetHub
Copy link

???

@HyukjinKwon
Copy link
Member Author

@JohnGetHub could you elaborate if I did something wrong or misunderstood?

@JohnGetHub
Copy link

no,open a joke

@felixcheung
Copy link
Member

felixcheung commented Apr 9, 2017 via email

@asfgit asfgit merged commit d39c4ec into apache:asf-site Apr 10, 2017
@HyukjinKwon HyukjinKwon deleted the r-code-guide branch April 10, 2017 09:01
ghost pushed a commit to dbtsai/spark that referenced this pull request Apr 16, 2017
…inst project's code style

## What changes were proposed in this pull request?

Currently, multi-dot separated variables in R is not allowed. For example,

```diff
 setMethod("from_json", signature(x = "Column", schema = "structType"),
-          function(x, schema, asJsonArray = FALSE, ...) {
+          function(x, schema, as.json.array = FALSE, ...) {
             if (asJsonArray) {
               jschema <- callJStatic("org.apache.spark.sql.types.DataTypes",
                                      "createArrayType",
```

produces an error as below:

```
R/functions.R:2462:31: style: Words within variable and function names should be separated by '_' rather than '.'.
          function(x, schema, as.json.array = FALSE, ...) {
                              ^~~~~~~~~~~~~
```

This seems against https://google.github.io/styleguide/Rguide.xml#identifiers which says

> The preferred form for variable names is all lower case letters and words separated with dots

This looks because lintr by default https://github.com/jimhester/lintr follows http://r-pkgs.had.co.nz/style.html as written in the README.md. Few cases seems not following Google's one as "a few tweaks".

Per [SPARK-6813](https://issues.apache.org/jira/browse/SPARK-6813), we follow Google's R Style Guide with few exceptions https://google.github.io/styleguide/Rguide.xml. This is also merged into Spark's website - apache/spark-website#43

Also, it looks we have no limit on function name. This rule also looks affecting to the name of functions as written in the README.md.

> `multiple_dots_linter`: check that function and variable names are separated by _ rather than ..

## How was this patch tested?

Manually tested `./dev/lint-r`with the manual change below in `R/functions.R`:

```diff
 setMethod("from_json", signature(x = "Column", schema = "structType"),
-          function(x, schema, asJsonArray = FALSE, ...) {
+          function(x, schema, as.json.array = FALSE, ...) {
             if (asJsonArray) {
               jschema <- callJStatic("org.apache.spark.sql.types.DataTypes",
                                      "createArrayType",
```

**Before**

```R
R/functions.R:2462:31: style: Words within variable and function names should be separated by '_' rather than '.'.
          function(x, schema, as.json.array = FALSE, ...) {
                              ^~~~~~~~~~~~~
```

**After**

```
lintr checks passed.
```

Author: hyukjinkwon <[email protected]>

Closes apache#17590 from HyukjinKwon/disable-dot-in-name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants