You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Argument hugging**: When function arguments can fit on a single line and the last argument's value starts on the same line as the opening parenthesis, the formatter keeps a compact format. Otherwise, it expands to multiple lines with proper indentation.
169
169
170
+
**Nested function calls** are formatted with hugging when appropriate:
171
+
172
+
```r
173
+
# Before formatting
174
+
result<- outer(inner(a,b),other(c,d))
175
+
176
+
# After formatting
177
+
result<- outer(inner(a, b), other(c, d))
178
+
```
179
+
170
180
### Function Definitions
171
181
172
182
Function definitions follow consistent formatting rules for parameters and body structure:
**Single line functions**: When the function body is a single expression, braces can be omitted if the expression starts on the same line. **Multi-line functions**: Always receive braces, even when the body starts on the same line as the function declaration.
199
+
186
200
**Anonymous functions** (lambda expressions) are also properly formatted:
187
201
188
202
```r
189
203
# Before formatting
190
-
apply(matrix,1,\(row)sum(row,na.rm=TRUE))
204
+
lapply(data,\(x)x+1)
191
205
192
206
# After formatting
193
-
apply(matrix, 1, \(row) sum(row, na.rm=TRUE))
207
+
lapply(data, \(x) x+1)
194
208
```
195
209
196
210
**Body formatting**: If a function definition spans multiple lines or has a multiline condition, non-braced bodies are automatically wrapped in braces for consistency.
String literals receive intelligent quote normalization. The formatter prefers double quotes (`"`) unless the string contains unescaped double quotes:
293
301
294
302
```r
295
303
# Before formatting
296
-
message<-"Hello world"
304
+
message<-'Hello world'
297
305
quoted_content<-'Say "hello"'
298
306
299
307
# After formatting
300
308
message<-"Hello world"
301
309
quoted_content<-'Say "hello"'
302
310
```
303
311
304
-
**Quote selection**: The formatter prefers single quotes unless the string content contains unescaped double quotes. This helps avoid unnecessary escaping while maintaining readability.
305
-
306
312
### Subsetting and Member Access
307
313
308
314
**Bracket subsetting** follows the same formatting rules as function calls:
309
315
310
316
```r
311
317
# Before formatting
312
318
data[row_index,column_index]
313
-
matrix[i=1,j=2,drop=FALSE]
314
-
315
-
# After formatting
316
-
data[row_index, column_index]
317
-
matrix[i=1, j=2, drop=FALSE]
318
-
```
319
-
320
-
**Double bracket subsetting** for list/environment access:
321
-
322
-
```r
323
-
# Before formatting
324
319
environment[["variable_name"]]
325
-
nested_list[[key1]][[key2]]
326
-
327
-
# After formatting
328
-
environment[["variable_name"]]
329
-
nested_list[[key1]][[key2]]
330
-
```
331
-
332
-
**Member access operators** (`$` and `@`):
333
-
334
-
```r
335
-
# Before formatting
336
320
object$member_variable
337
-
s4_object@slot_name
338
321
339
322
# After formatting
323
+
data[row_index, column_index]
324
+
environment[["variable_name"]]
340
325
object$member_variable
341
-
s4_object@slot_name
342
326
```
343
327
344
328
**Namespace operators** (`::` and `:::`):
@@ -359,9 +343,9 @@ Unary operators receive appropriate spacing based on their type and context:
359
343
360
344
```r
361
345
# Before formatting
362
-
result=!condition
363
-
number=-42
364
-
formula=~response+predictor
346
+
result=!condition
347
+
number=-42
348
+
formula=~response+predictor
365
349
366
350
# After formatting
367
351
result=!condition
@@ -371,100 +355,26 @@ formula = ~ response + predictor
371
355
372
356
**Special spacing rule**: The `~` (formula) operator gets a space when followed by complex expressions, but not when followed by simple identifiers.
373
357
374
-
## Compound Expressions
375
-
376
-
Roughly excels at formatting complex, nested expressions while maintaining readability. Here are some examples of how compound expressions are handled:
0 commit comments